bcherny/tsoption

add extra overload for from?

emmanueltouzery opened this issue · 0 comments

I'm not actually planning to use tsoption, but I was looking at its design: nice job!

could be worth it maybe to add a third overload for the Option.from interface:

from<T>(value: T|undefined): Option<T>

The reason is that without it, for the extremely common case:

let x : number|undefined;
const y = Option.from(x);

You get y inferred to as Some<number|undefined> which is not really useful. With the extra overload that I suggest, the issue goes away and it's properly inferred as Option<number>.

EDIT Otherwise without the overload, one can always do Option.from<number>(x) of course.