microsoft / microsoft/TypeScript
Incorrect type inference for Record with symbol key
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
TypeScript Version: Nightly
Search Terms: Record, Symbol, symbol as index
Code
export type SN = Record<symbol, number>
const s = Symbol()
const sn: SN = {}
const n = sn[s] // n is of type any instead of number
Expected behavior:
A Record with symbols as key should allow to access properties by symbol with correct type
Actual behavior:
All keys are any type.
Related Issues: #1863
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 the example in the issue using the TypeScript Nightly playground or the shown TypeScript version, then trace the compiler's handling of indexed access on Record<symbol, number>. Compare the inferred type of sn[s] with the expected number and use the related issue #1863 for context. Done means symbol-keyed Record access is inferred as number rather than any, with a regression test covering the example.
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
- 45/100