-
Notifications
You must be signed in to change notification settings - Fork 13k
Open
Labels
Experimentation NeededSomeone needs to try this out to see what happensSomeone needs to try this out to see what happensSuggestionAn idea for TypeScriptAn idea for TypeScript
Description
TypeScript Version: [email protected]
Search Terms: tagged disjoint union generic
This issue stems from a question I asked on StackOverflow that @jcalz generously researched for me. I adapted his example to be a closer parallel to the example given in #17110.
Code
interface A { a: string; }
interface W {
x: A
}
function foo<W1 extends W>(w: W1, k: keyof W1['x']) {
w.x[k]; // Type 'keyof W1["x"]' cannot be used to index type 'A'.
const x: W1['x'] = w.x; // Okay
x[k] // Okay
}
Expected behavior:
Same as #17110. However, unlike #17110, W['x']
is only A
instead of A | B | undefined
. The explanation given as to why #17110 was not a bug was:
The constraint of
keyof W1["x"]
iskeyof (A | B)
, which simplifies tokeyof A & keyof B
, which isnever
(because there are no common properties).
However, here keyof W1['x']
is keyof A
which is not never
.
Actual behavior:
Same as #17110.
Related Issues: #17110
chanced, cdpark0530 and mkantorjcalz
Metadata
Metadata
Assignees
Labels
Experimentation NeededSomeone needs to try this out to see what happensSomeone needs to try this out to see what happensSuggestionAn idea for TypeScriptAn idea for TypeScript