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
4.6 example
4.7 example
π» 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.
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
4.6 example
4.7 example
π» Code
Also it works in 4.7 with optional (
?) removed fromTypeHandlersindex.π Actual behavior
The code won't compile.
π Expected behavior
The code should compile.