-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issue
Milestone
Description
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
export const KEY = Symbol('KEY')
export interface Tree {
[KEY]?: string
[name: string]: Tree
}
// Here I get a type problem
export const tree: 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:
yortus and DeTeam
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issue