Skip to content

No type inference from callback in mapped type #21273

@ghost

Description

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.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions