Typescript: Constraints cannot be proven in mapped types combination

Created on 20 Dec 2016  路  7Comments  路  Source: microsoft/TypeScript

TypeScript Version: 2.1.4 / nightly (2.2.0-dev.20161219)

Code

type A<T> = () => T;
type B<T, C extends A<T>> = C;
type As<Ts> = {
    [P in keyof Ts]: A<Ts[P]>;
};

type Failing<Ts, Cs extends As<Ts>> = {
    [P in keyof Ts]: B<Ts[P], Cs[P]>;
//                            ~~~~~ Type 'Cs[P]' does not satisfy the constraint 'A<Ts[P]>'.
};

Expected behavior:

No errors, the constraint has been proven

Actual behavior:

Error in Failing type at B<Ts[P], Cs[P]>: Type 'Cs[P]' does not satisfy the constraint 'A

Note

If I change A<T> to be just T (type A<T> = T;), all compiles just fine.

Bug Fixed

Most helpful comment

Guess what we're spending the swag budget on this year

All 7 comments

might be related #8459 which presumably growing from #8397 or even this one #3410

image

ha! don't downvote me, downvote the design team who is making typescript is the only language out there that sacrifices correctness for "convenience" of use, this is blatant and unprecedented

Guess what we're spending the swag budget on this year

Repro with some thing renamed / simplified a little

  interface Thing { blah };
  type B<C extends Thing> = { m: C };
  type ThingMap<M> = {
    [P in keyof M]: Thing;
  };

  type Failing<T, Cs extends ThingMap<T>> = {
    foo: B<Cs[keyof T]>;
  };

  type Passing<T> = {
    foo: B<ThingMap<T>[keyof T]>;
  };

@RyanCavanaugh Seems like your repro is fixed now, but @Igorbek 's repro still throws an error.

https://github.com/Microsoft/TypeScript/issues/15957

... Guess what we're spending the swag budget on this year...

test

should be fixed in latest.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Antony-Jones picture Antony-Jones  路  3Comments

seanzer picture seanzer  路  3Comments

siddjain picture siddjain  路  3Comments

wmaurer picture wmaurer  路  3Comments

jbondc picture jbondc  路  3Comments