-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issue
Milestone
Description
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 TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issue