-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
TS 4.1 regression in type assertion of generic mapped type #41617
Comments
I tried to reduce the repro, but it reproduces only when all these present:
|
@typescript-bot run repros |
Heya @orta, I've started to run the code sample repros for you. Here's the link to my best guess at the log. |
👋 Hi, I'm the Repro bot. I can help narrow down and track compiler bugs across releases! This comment reflects the current state of the 2 repros in this issue running against the nightly TypeScript. Issue body code block by @Igorbek ❌ Failed: -
👍 Compiled Historical InformationIssue body code block by @Igorbek
Comment by @weswigham
|
Here's the problem, but without control flow involved: interface A { x: number }
declare function isA(a: unknown): a is A;
type FunctionsObj<T> = {
[K in keyof T]: () => unknown
}
function g<
T extends FunctionsObj<T>,
M extends keyof T
>(a2: ReturnType<T[M]>, x: A) {
x = a2; // shouldn't be allowed, but is
} This is a bug in our subtyping rules, not control flow (which would undoubtedly be easier to fix). @typescript-bot run repros |
Heya @weswigham, I've started to run the code sample repros for you. Here's the link to my best guess at the log. |
Looks like the root cause is our change in 4.1 to |
TypeScript Version: 4.1.2
Search Terms: CFA, narrowing, generic, mapped type, conditional type, type assertion
Code
Expected behavior:
Type of
a2
should be narrowed toReturnType<T[M]> & A
It works this way in TS 4.0
Actual behavior:
Type of
a2
remains onlyReturnType<T[M]>
Playground Link: https://www.typescriptlang.org/play?ts=4.1.0-beta#code/JYOwLgpgTgZghgYwgAgILIN7IB4C5kgCuAtgEbTIC+AUNQCYQIA2cUKMhICYwA9iMmABnVAAo4+TgGsQvAO4gAlPjiChaANy0wATwAOKAGKdufEEIDypAFYAeACoA+ZAF5M1ZMgDaAaUECpCB1eGGR7AF18UUVXZ2lZBWoaag4uHn5kAHNbDzDkCGxIEDp1YzSzSxsHRwAaXIBZfMKIYvVA4ND7akdxACZ8ACUIMEIoEHt9CAcvevDHGIxc4FDRYTE4XsUF3M8NgDpsZAB6I-yoKF4oXJoaIA
The text was updated successfully, but these errors were encountered: