-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Labels
DuplicateAn existing issue was already createdAn existing issue was already createdFix AvailableA PR has been opened for this issueA PR has been opened for this issue
Milestone
Description
Bug Report
π Search Terms
4.7
π Version & Regression Information
Such code became broken in 4.7. It works as expected in 4.6.
β― Playground Link
π» Code
type TypesMap = {
[0]: { foo: 'bar'; };
[1]: { a: 'b'; };
};
type P<T extends keyof TypesMap> = { t: T; } & TypesMap[T];
type TypeHandlers = {
[T in keyof TypesMap]?: (p: P<T>) => void;
};
const typeHandlers: TypeHandlers = {
[0]: (p) => console.log(p.foo),
[1]: (p) => console.log(p.a),
};
const onSomeEvent = <T extends keyof TypesMap>(p: P<T>) =>
typeHandlers[p.t]?.(p);Also it works in 4.7 with optional (?) removed from TypeHandlers index.
π Actual behavior
The code won't compile.
π Expected behavior
The code should compile.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
DuplicateAn existing issue was already createdAn existing issue was already createdFix AvailableA PR has been opened for this issueA PR has been opened for this issue