Skip to content

Inconsistent type inference for empty function type in mapped types #12573

Description

@HerringtonDarkholme

TypeScript Version: nightly

Code

declare function one<T>(handler: (t: T) => void): T
var empty = one(() => {}) // inferred as {}, expected

type Handlers<T> = { [K in keyof T]: (t: T[K]) => void }
declare function on<T>(handlerHash: Handlers<T>): T
var hashOfEmpty = on({
    test: () => {}
})
// inferred as {test(): void}, expected {test: {}}

Expected behavior:

hashOfEmpty is inferred as {test: {}}

Actual behavior:

hashOfEmpty is inferred as {test(): {}}

Metadata

Metadata

Assignees

No one assigned

    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

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions