Closed
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