Continuing #17110 - Given generic W extends { x: A }
should be able to use keyof W['x']
to index w.x
#33181
Labels
Experimentation Needed
Someone needs to try this out to see what happens
Suggestion
An idea for TypeScript
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
Expected behavior:
Same as #17110. However, unlike #17110,
W['x']
is onlyA
instead ofA | B | undefined
. The explanation given as to why #17110 was not a bug was:However, here
keyof W1['x']
iskeyof A
which is notnever
.Actual behavior:
Same as #17110.
Playground Link: http://www.typescriptlang.org/play/#code/JYOwLgpgTgZghgYwgAgILIN7LgLmQZzClAHMBuZAXwChrRJZEUB1Ta5D5ADz1WpuowAriARhgAexDIYEiQB5mARmQQukEABN8yZgD4AFAHc8ygDTIA1nksQAnhJi6lAbQDkXNwF0AlGw5GAHRcLpZeFAD0EcgAKnYADihutg5Oyi4ARFwZXm7ICHAgIBJgyABGKEL4EJrIYBLIoJpqdQlJqG6BtBwIUoTcpq4e3sgAvMhBXJHRAPKWcHbs3KFeyFHIcwv8QA
Related Issues: #17110
The text was updated successfully, but these errors were encountered: