Skip to content

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

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
user471 opened this issue Jul 18, 2018 · 2 comments
Closed
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@user471
Copy link

user471 commented Jul 18, 2018

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

@user471
Copy link
Author

user471 commented Jul 18, 2018

Is there any workaround?

@ahejlsberg
Copy link
Member

This is fixed by #30568.

@ahejlsberg ahejlsberg added the Fixed A PR has been merged for this issue label Mar 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

6 participants