Skip to content

Function parameter type inference doesn't work with keyof of generic type #25759

Closed
@user471

Description

@user471

TypeScript Version: 3.1.0-dev.201xxxxx

Search Terms:
function parameter type inference keyof generic
Code

function foo1<T>(foo: T, bar: {[key in keyof {foo: number}] : (x: T) => number }) {
}

function foo2<T>(foo: T, bar: {[key in keyof T] : (x: T) => number }) {
}

foo1({foo: 1}, {foo: x1 => x1.foo + 1})
foo2({foo: 1}, {foo: x2 => x2.foo + 1})

Expected behavior:
x2 has type {foo:number}
Actual behavior:
Compiler error
TS7006: Parameter 'x2' implicitly has an 'any' type.

x1 has type {foo:number}
but
x2 has type any

Playground Link:
Playground

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions