-
Notifications
You must be signed in to change notification settings - Fork 12.8k
A bug of type system? #18909
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
It's not working for me for src/a.ts(47,42): error TS2344: Type 'obj1[k]' does not satisfy the constraint '{ [p in K]: obj1[k][p]; }'.
Type '{ a1: string; a2: string; } | { b1: string; b2: string; }' is not assignable to type '{ [p in K]: obj1[k][p]; }'.
Type '{ a1: string; a2: string; }' is not assignable to type '{ [p in K]: obj1[k][p]; }'. I also don't see |
it's working in [email protected] @Andy-MS |
I'm not sure what the correct behavior should be here... CC @sandersn |
This is almost certainly due to the empty-intersection-elimination PR #18438. I'm constructing a smaller repro that's easier to understand so I can see whether the new behaviour is correct. |
Briefly, type strictKeys<T extends Record<K, any>, K extends string> = T;
// OR, even smaller:
type strictKeys<T, K extends keyof T> = T; Circular constraints not reportedtype strictKeys<T extends { [P in K]: T[P] }, K extends string> = T;
~
circular constraint for 'T' The underlying error is that strictKeys has a circular constraint, which is illegal and doesn't have well-defined semantics. However, this is not reported and the compiler does its best to produce some kind of type from instantiations of strictType. There seem to be other constructions that don't report circular constraints, such as index signatures. Impossible intersections break index access typesIn 2.5.2 and earlier, the first error is hidden by another limitation of the compiler: indexing a type with a union that includes impossible intersections just produces any: let good: Base['a' | 'b'] // ==> { a1, a2 } | { b1, b2 }
let bad: Base['a' | 'b' | ('a' & 'b') | ('b' & 'a')] // ==> any #18438 now removes impossible intersections from unions, making It also means that which means that Improvements to impossible-intersection-removalSome recent change further improved impossible intersection removal. If you build from master, you'll see errors for both |
@sandersn Oh thank you for your answer, I'm still learning type system of typescript. |
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed. |
When i delete 'a' or 'b' or 'c' from 'obj2', 'T2' is ok.
Why?
The text was updated successfully, but these errors were encountered: