Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Constraints cannot be proven in mapped types combination #13039

Closed
Igorbek opened this issue Dec 20, 2016 · 7 comments
Closed

Constraints cannot be proven in mapped types combination #13039

Igorbek opened this issue Dec 20, 2016 · 7 comments
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@Igorbek
Copy link
Contributor

Igorbek commented Dec 20, 2016

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<Ts[P]>'.

Note

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

@zpdDG4gta8XKpMCd
Copy link

zpdDG4gta8XKpMCd commented Dec 20, 2016

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

image

@zpdDG4gta8XKpMCd
Copy link

zpdDG4gta8XKpMCd commented Dec 20, 2016

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

@RyanCavanaugh
Copy link
Member

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

@RyanCavanaugh
Copy link
Member

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 RyanCavanaugh added the Bug A bug in TypeScript label Dec 21, 2016
@falsandtru
Copy link
Contributor

falsandtru commented Jan 22, 2017

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

@zpdDG4gta8XKpMCd
Copy link

zpdDG4gta8XKpMCd commented May 19, 2017

#15957

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

test

@mhegazy mhegazy added this to the TypeScript 2.8 milestone Apr 12, 2018
@mhegazy mhegazy added the Fixed A PR has been merged for this issue label Apr 12, 2018
@mhegazy
Copy link
Contributor

mhegazy commented Apr 12, 2018

should be fixed in latest.

@mhegazy mhegazy closed this as completed Apr 12, 2018
@microsoft microsoft locked and limited conversation to collaborators Jul 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

5 participants