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
I'm trying to use both the index signature in my interface and some symbol fields. They don't seem to work very well together.
Code
exportconstKEY=Symbol('KEY')exportinterfaceTree{[KEY]?: string[name: string]: Tree}// Here I get a type problemexportconsttree: Tree={'a': {[KEY]: 'value1','x': {[KEY]: 'value2'}},'b': {[KEY]: 'value3'},'c': {[KEY]: 'value4'}}
Expected behavior:
I think there're two options here:
Either complain about things on the type level (like if one'd use key (just a string field name) instead of a symbol [KEY])
Or allow such usage together with access later const s: Tree = tree['c']; const s: string = tree['c'][KEY]
Actual behavior:
Property '[KEY]' is incompatible with index signature.
Playground Link:
Related Issues:
I think that maybe the following ones are related in a way:
I think #21217 was meant to fix this, but this shows there is still a problem. Simpler repro:
exportconstSYM=Symbol('a unique symbol');exportinterfaceI{[SYM]: 'sym';[x: string]: 'str';}leta: I={[SYM]: 'sym'};// ERROR: 'sym' is not assignable to 'str'letb: I={[SYM]: 'str'};// ERROR: 'str' is not assignable to 'sym'
indexTypesRelatedTo inside isRelatedTo doesn't filter out symbol-keyed properties for its eachPropertyRelatedTo check, which is the actual root issue for this one.
I'm trying to use both the index signature in my interface and some symbol fields. They don't seem to work very well together.
Code
Expected behavior:
I think there're two options here:
key
(just a string field name) instead of a symbol[KEY]
)const s: Tree = tree['c']; const s: string = tree['c'][KEY]
Actual behavior:
Playground Link:
Related Issues:
I think that maybe the following ones are related in a way:
The text was updated successfully, but these errors were encountered: