jklmli / monapt

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

Compilation error with monapt@1.0.1 and typescript@2.4.1 #17

Closed stefanrmeier closed 7 years ago

stefanrmeier commented 7 years ago

I just upgraded from monapt 0.7 to 1.0.1 and got the following error when I compile my project:

ERROR in [at-loader] ./node_modules/monapt/dist/src/option/some.d.ts:5:15
    TS2420: Class 'Some<A>' incorrectly implements interface 'Option<A>'.
  Types of property 'getOrElse' are incompatible.
    Type '<B, A extends B>(this: Some<A>, defaultValue: () => B) => B' is not assignable to type '<B, A extends B>(this: Option<A>, defaultValue: () => B) => B'.
      The 'this' types of each signature are incompatible.
        Type 'Option<A>' is not assignable to type 'Some<B>'.
          Property 'value' is missing in type 'Option<A>'.

ERROR in [at-loader] ./node_modules/monapt/dist/src/try/failure.d.ts:7:15
    TS2420: Class 'Failure<A>' incorrectly implements interface 'Try<A>'.
  Types of property 'getOrElse' are incompatible.
    Type '<B, A extends B>(this: Failure<A>, defaultValue: () => B) => B' is not assignable to type '<B, A extends B>(this: Try<A>, defaultValue: () => B) => B'.
      The 'this' types of each signature are incompatible.
        Type 'Try<A>' is not assignable to type 'Failure<B>'.
          Property 'error' is missing in type 'Try<A>'.

ERROR in [at-loader] ./node_modules/monapt/dist/src/try/success.d.ts:7:15
    TS2420: Class 'Success<A>' incorrectly implements interface 'Try<A>'.
  Types of property 'getOrElse' are incompatible.
    Type '<B, A extends B>(this: Success<A>, defaultValue: () => B) => B' is not assignable to type '<B, A extends B>(this: Try<A>, defaultValue: () => B) => B'.
      The 'this' types of each signature are incompatible.
        Type 'Try<A>' is not assignable to type 'Success<B>'.
          Property 'value' is missing in type 'Try<A>'.

It seems that the error comes from following declarations in the typedef:

some.d.ts

private value;

failure.d.ts

private error;
readonly exception: Error;

success.d.ts

private value;

When commenting out these lines, it compiles without error. After some research, it found this statement "[T]he root cause here is that you declared destination as protected. A protected method can only be implemented or overridden by a class that inherits (through extends, not implements) the class which first declared the method." (source. Probably the same is true for private variables.

jklmli commented 7 years ago

Hey - thanks for the bug report. From what I can tell, this looks like an issue specific to TypeScript 2.4.x. I'll dig into this more.

Also, I'll leave myself a note to set up a test matrix to build against multiple versions of TypeScript.

jklmli commented 7 years ago

I made some changes that may have fixed this in https://github.com/jiaweihli/monapt/commit/7a63ffef7d066f6d56e82307d4334ec384251085. It's in 1.0.4.

Can you take a look and see if that makes your compile errors go away?

stefanrmeier commented 7 years ago

Thanks! That was very quick. It compiles without any error now.

jklmli commented 7 years ago

Glad to hear things are working - thanks for letting me know! 😄