Skip to content

Function type inference #38883

@schusovskoy

Description

@schusovskoy

TypeScript Version: 3.9.2

Search Terms:
function type

Code

type GetKeys = <T>(obj: T) => (keyof T)[]
const keys: GetKeys = Object.keys

Expected behavior:
The last line should throw an error, cause string[] is not assignable to (keyof T)[]

Actual behavior:
No error

Playground Link: https://www.typescriptlang.org/play/index.html?ssl=1&ssc=1&pln=2&pc=34#code/C4TwDgpgBA4hwGkIgM5QLxQDwBUB8AFAPYBGAVgFxQ4CUGeUBA1skQGbU0DaAugFABjIgDsUwKC1RU4iZGkwB5chAHAAdJJRA

Related Issues:
Maybe that #38879

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions