microsoft / microsoft/TypeScript
Declaring index signature based on property type gives invalid error
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
TypeScript Version: latest, demonstrable on playground (links below)
Search Terms: index signature diagnostics property type
Code:
interface BaseNode {
kind: string;
[key: string]: string | TokenNode["data"];
}
interface TokenNode extends BaseNode {
kind: 'token';
data: TokenData;
}
interface TokenData {
offset: number;
width: number;
leading_width: number;
trailing_width: number;
}
Expected behavior:
No errors, as the code is correct.
Actual behavior:
An error on interface TokenNode:
Interface 'TokenNode' incorrectly extends interface 'BaseNode'.
Index signature is missing in type 'TokenNode'.
HOWEVER if I change TokenNode["data"] to its value TokenData, the error goes away.
Playground Link:
Code above displaying the error
Code above with the fix, no errors
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce both linked TypeScript Playground examples, comparing the indexed-access form with the equivalent TokenData form. Trace the type-checking behavior for the BaseNode and TokenNode interface declarations; done means the indexed-access version no longer reports the invalid inheritance error while the existing valid case remains error-free.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100