-
Notifications
You must be signed in to change notification settings - Fork 12.8k
TS2345 error with derivated types from a map of types #35613
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
Indexed access produces intersection type => most likely caused by #30769. |
TS doesn't know that this is OK to do. You could have written this, which would be seen equivalently: function processContent<T extends A>(content1: Content<T>, content2: Content<T>) {
parserPayload[content1.type](content2.payload);
}
declare const a: Content<A.a>, b: Content<A.b>;
// Causes a runtime error, but is an OK call
processContent(a, b); |
Duplicate #31445 |
BTW, isn't that a kind of bug that TS doesn't check? There are a lot of business logic bugs with correct typings that TS isn't able to catch and that's OK. Isn't the bug you're exemplifying one of that kind? Thank you for your rapid response! |
That's a type error, not a business logic error. You can construct examples that observe a |
TypeScript Version: 3.7.2
Search Terms: ts2345 derivated type error
I really don't know how to describe this bug in short terms.
Code
Expected behavior: To correctly know that
PayloadMap[key]
is in fact the same asPayloadMap[T]
sincekey
matchesT
.Actual behavior:
Playground Link: https://www.typescriptlang.org/play/?ssl=1&ssc=1&pln=30&pc=2#code/KYOwrgtgBAglDeAoKKoEMoF4oHI04BplUAjLXEnRAX0UQEsQAXYAJwDM0BjYKAeRIArOElRQADqwD24gIwAuKAGcmrRgHMA3DQbM2nHvyEAhBMRSSZAJkXgIJNttqImAT3G8ACmlcAbKWgAJgCyaOLkoqgA2jAAdGgAuooCwtpiMbEkSUaCxk50bh5QAMJSeswAPAAqUMAAHiwggUqwAHwR5lCFwIpVaajiPv5Bit5+ASFhUVUJ+YjsYCBcTPRlEtI8Skql5UzVtQ2gzW0AFFxljUyKO5fVrQCUZmKDrEpsY8OBUee7sd0JZwuoCYsUG4yC9zmPxUEjQr3eQwmingUCiAGtgK4oIxYNkTmDPqNEUFQuJ0ZiEo9MO00CAsdQOmI0IoCRMsO1WUFQdI5EQxCQWcTAuzYeDAtzrERqEA
Related Issues:
The text was updated successfully, but these errors were encountered: