microsoft / microsoft/TypeScript
Elementwise elaboration fails to be found for properties mixed with incompatible index signatures using intersections
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.4k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
🔎 Search Terms
elementwise elaboration errors write type index signature intersection
🕗 Version & Regression Information
- This is the behavior in every version I tried
⏯ Playground Link
💻 Code
const test: { [k: string]: number } & { foo: string } = { foo: "bar" };
🙁 Actual behavior
test variable gets highlighted
🙂 Expected behavior
I'd expect foo property in the source to get highlighted
Additional information about the issue
I don't really expect this to get any meaningful priority ;p it's just something interesting that I noticed while investigating some legitimate question as to why an error is not on the property itself in a more complex situation. Such intersections are flawed on principle so 🤷♂️
This happens because elaborateElementwise uses getBestMatchIndexedAccessTypeOrUndefined and that prefers concrete properties on intersections over index signatures. The problem is that you can read such dubious properties from the type (and it has a matching type in the example above so it doesn't become an elementwise candidate) but you can't quite write to them.
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 linked TypeScript Playground, then inspect elaborateElementwise and getBestMatchIndexedAccessTypeOrUndefined, which the issue identifies as the relevant path. Confirm how the intersection's concrete property is preferred over its index signature, and consider the issue done when the source foo property is highlighted rather than only the test variable.
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