You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
constsym=Symbol("")typeOrig={[k: string]: any,str: any,[sym]: any}typeOkay=Exclude<keyofOrig,never>// type Okay = string | number | typeof symtypeRemapped={[KinkeyofOrigas{}extendsRecord<K,any> ? never : K]: any}/* type Remapped = { str: any; [sym]: any;} */// no string index signature, right?typeOops=Exclude<keyofRemapped,never>// type Oops = typeof sym <-- what happened to "str"?
🙁 Actual behavior
keyof Remapped is typeof sym.
🙂 Expected behavior
keyof Remapped should be typeof sym | "str" because Remapped is {str: any, [sym]: any}.
It looks like the bug reported in #41966 was fixed for most cases, but not when the object type being remapped has a symbol-valued key. Not sure why. I ran into this when answering this Stack Overflow question.
The text was updated successfully, but these errors were encountered:
There’s a clue as to what’s going on if you change the string index signature to a symbol index signature—we lose the [sym] key instead of the "str" key 🤔
Bug Report
This is a sequel to #41966.
🔎 Search Terms
keyof, key remapping, index signature, symbol, known keys
🕗 Version & Regression Information
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
keyof Remapped
istypeof sym
.🙂 Expected behavior
keyof Remapped
should betypeof sym | "str"
becauseRemapped
is{str: any, [sym]: any}
.It looks like the bug reported in #41966 was fixed for most cases, but not when the object type being remapped has a
symbol
-valued key. Not sure why. I ran into this when answering this Stack Overflow question.The text was updated successfully, but these errors were encountered: