jklmli / monapt

Options, Tries, and Futures for JavaScript / TypeScript
MIT License
172 stars 13 forks source link

TS 2: Change None from Option<any> to Option<never> #12

Closed OliverJAsh closed 7 years ago

OliverJAsh commented 7 years ago

In TS 2, the following doesn't error

const fn: Option<string> = true ? new Some(1) : None
// Expected error but none

I think that's because None is declared as Option<any>. We need to change it to Option<never>:

const fn: Option<string> = true ? new Some(1) : None as Option<never>
// Error: number is not assignable to string

How do you plan to manage this change in a backwards compatible way? I'm using Monapt in TS 2, so would love to see this change.

jklmli commented 7 years ago

It might be possible to hack the type system with a type alias:

type never = never | any

If that's invalid in TS 2, we can wrap it in a try/catch - we'll only pay the price of the try/catch once during module initialization.

I don't think we need to do a true backport and recreate the never type in TS 1 - this can be a strict improvement with a new minor version. I'll play around with it and see if it's possible nonetheless.

jklmli commented 7 years ago

TypeScript 2.0 is out!

Will get to this very soon :)