jklmli / monapt

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

TypeScript 2.5.3 breaks typings #20

Closed jchapuis closed 6 years ago

jchapuis commented 6 years ago

Latest TypeScript release has introduced some changes that break Option typings, I'm now getting the following error:

  Types of property 'getOrElse' are incompatible.
    Type '<B, A extends B>(this: Option<A>, defaultValue: () => B) => B' is not assignable to type '<B, A extends B>(this: Option<A>, defaultValue: () => B) => B'. Two different types with this name exist, but they are unrelated.
      The 'this' types of each signature are incompatible.
        Type 'Option<A>' is not assignable to type 'Option<B>'.
          Type 'A' is not assignable to type 'B'.
            Type 'B' is not assignable to type 'B'. Two different types with this name exist, but they are unrelated.

for the following code which worked perfectly in 2.5.2:

import {Option, Some, None} from "monapt";
import {isUndefined} from "util";

export function tryParseJSON<T>(s: string | undefined): Option<T>  {
    if (isUndefined(s)) {
        return None;
    }
    try {
        const o = JSON.parse(s) as T;
        if (o) {
            return new Some(o);
        } else {
            return None;
        }
    } catch (e) {
        return None;
    }
}
jklmli commented 6 years ago

Thanks for reporting this, I'll look into this tomorrow.

jklmli commented 6 years ago

This issue is similar to an older issue: https://github.com/jiaweihli/monapt/commit/7a63ffef7d066f6d56e82307d4334ec384251085

It looks like the trick with upper bounds and self-types is failing with inheritance on interfaces - I'll see if I can find a workaround.

jklmli commented 6 years ago

Sorry for the wait - does that fix your issue?