Skip to content

Nested callbacks are not contextually typed with a type parameter dependent type queryΒ #52575

Closed
@dragomirtitian

Description

@dragomirtitian

Bug Report

πŸ”Ž Search Terms

nested callbacks contextual types

πŸ•— Version & Regression Information

  • This changed between versions 5.0.0-dev.20221216 and 5.0.0-dev.20221217

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

export interface Event<T> {
    callback: (response: T) => void;
    nested: {
        callback: (response: T) => void;
    }
}

export type CustomEvents = {
    a: Event<string>
    b: Event<number> // If only one candidate type exists it works
};

declare function emit<T extends keyof CustomEvents>(type: T, data: CustomEvents[T]): void

emit('a', {
    callback: (r) => {}, // r is string in 4.9 and 5.0
    nested: {
        callback: (r) => { // r is string in 4.9 and an error in 5.0

        },
    },
});

πŸ™ Actual behavior

The parameter of the callback in nested is not typed and gives an error : Parameter 'r' implicitly has an 'any' type.

πŸ™‚ Expected behavior

The parameter of the callback in nested is typed as string, same as in 4.9 and same as for the top level callback

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions