Skip to content

Method argument types aren't inferred from mapped types #24694

Closed
@falsandtru

Description

@falsandtru

TypeScript Version: master

Search Terms:

Code

declare function f<T extends object>(data: T, handlers: { [P in keyof T]: (value: T[P], prop: P) => void; }): void;
f({ data: 0 }, {
  data(value, key) {
  },
});

Should also work with optional.

declare function f<T extends object>(data: T, handlers: { [P in keyof T]?: (value: T[P], prop: P) => void; }): void;
f({ data: 0 }, {
  data(value, key) {
  },
});

Expected behavior:

pass

Actual behavior:

$ node built/local/tsc.js --strictNullChecks --noImplicitAny index.ts
index.ts:3:8 - error TS7006: Parameter 'value' implicitly has an 'any' type.

3   data(value, key) {
         ~~~~~


index.ts:3:15 - error TS7006: Parameter 'key' implicitly has an 'any' type.

3   data(value, key) {
                ~~~

Playground Link:

Related Issues:

Metadata

Metadata

Assignees

Labels

Needs InvestigationThis issue needs a team member to investigate its status.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions