-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
DuplicateAn existing issue was already createdAn existing issue was already created
Description
Bug Report
π Search Terms
intersection type, index signature
π Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ
Tested in TS Playground for version 3.9 up to 4.6 nightly.
β― Playground Link
Playground link with relevant code
π» Code
type Grammar = {
rest: 'rest' // Error: "rest" is not assignable to "value"
[key: string]: 'value'
}
// No error - shouldn't this behave the same way?
type Grammar2 = {
rest: 'rest'
} & {
[key: string]: 'value'
}
// Compile error - Grammar2 type is essentially unusable
const grammar2: Grammar2 = {
rest: 'rest',
myKey: 'value'
}
π Actual behavior
- Only
Grammar
produces a compile error even though it is equivalent toGrammar2
. 'rest
' cannot be assigned to therest
property ofGrammar2
.
π Expected behavior
I'm not sure how this should behave.
Additional Context
Posting this issue due to a problem with @types/prismjs
. A Prism Grammar
has a [key: string]: GrammarValue
index signature AND special properties like rest
which are not assignable to GrammarValue
. How can I fix this in @types/prismjs
?
Metadata
Metadata
Assignees
Labels
DuplicateAn existing issue was already createdAn existing issue was already created