-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Some code became broken in 4.7 #49338
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Not sure what you mean by "narrowed by generic"? You're going to have to give more details about what's going wrong. "The code won't compile" isn't very helpful. |
I know. Sorry for that. But I can't figure out what exactly is wrong. Code that worked at 4.6 won't compile at 4.7 for some unclear reasons. It should work by my logic (and worked as expected prior 4.7). Compiler just throws some obscure errors. That's why I'm asking for help here. |
Ok, I figured out something. 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); But when I add optional ( 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); it works as expected at 4.6 (example), but broken at 4.7 (example). I don't know why |
Could be the same as #49242 |
Yeah. Too bad the error is very obscure and I wasn't even able to properly explain it. |
This is indeed a duplicate of #49242. |
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 fromTypeHandlers
index.π Actual behavior
The code won't compile.
π Expected behavior
The code should compile.
The text was updated successfully, but these errors were encountered: