Skip to content

No type inference from callback in mapped type #21273

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

Closed
ghost opened this issue Jan 18, 2018 · 1 comment
Closed

No type inference from callback in mapped type #21273

ghost opened this issue Jan 18, 2018 · 1 comment
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@ghost
Copy link

ghost commented Jan 18, 2018

TypeScript Version: 2.7.0-dev.20180118

Code

declare function conforms<T>(source: { [K in keyof T]: (val: T[K]) => boolean }): (value: T) => boolean;
conforms({ foo: (v: string) => false })({ foo: "foo" });

Expected behavior:

No error. T is inferred as { foo: string }.

Actual behavior:

T is inferred as { foo: {} }.

src/a.ts(2,10): error TS2345: Argument of type '{ foo: (v: string) => boolean; }' is not assignable to parameter of type '{ foo: (val: {}) => boolean; }'.
  Types of property 'foo' are incompatible.
    Type '(v: string) => boolean' is not assignable to type '(val: {}) => boolean'.
      Types of parameters 'v' and 'val' are incompatible.
        Type '{}' is not assignable to type 'string'.

Worked in 2.7.0-dev.20180116.

Detected in lodash on DefinitelyTyped.

@ghost
Copy link
Author

ghost commented Jan 18, 2018

@ahejlsberg It looks like this is a change from #21157. If I run git revert 1ae0b461f88e9a68c2b2ad51519611a2cc292fec (the first commit in that PR) I can compile without errors when testing with a local build.

@DanielRosenwasser DanielRosenwasser added the Bug A bug in TypeScript label Jan 18, 2018
@DanielRosenwasser DanielRosenwasser added this to the TypeScript 2.7.1 milestone Jan 18, 2018
@ahejlsberg ahejlsberg added the Fixed A PR has been merged for this issue label Jan 19, 2018
@microsoft microsoft locked and limited conversation to collaborators Jul 3, 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

2 participants