microsoft / microsoft/TypeScript
use [""] in object will lose ts check
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
🔎 Search Terms
This seems to be a TypeScript bug/limitation:
Originally posted by @KermanX in https://github.com/vuejs/language-tools/issues/3819#issuecomment-2173682276
🕗 Version & Regression Information
- This is a crash
- This changed between versions ______ and _______
- This changed in commit or PR _______
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about _________
- I was unable to test this on prior versions because _______
⏯ Playground Link
💻 Code
const a: Record<string, number> & { a1: 1 } = { } as any
a.a1
// ^?
a["a1"]
// ^?
a.a2
// ^?
a["a2"] // NO HINT!
// ^?
🙁 Actual behavior
a["a2"] // NO HINT!
🙂 Expected behavior
a["a2"] should be hint by typescript
Additional information about the issue
No response
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
Start with the linked TypeScript Playground and reproduce the difference between a.a2 and a["a2"] using the Record<string, number> intersection shown in the issue. Trace how these two property-access forms are checked and identify why the bracket form produces no hint. Done means a["a2"] receives the expected TypeScript hint consistently with a.a2.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100