microsoft / microsoft/TypeScript
Try enforcing contextual type of array literal elements
Open
Nobody has claimed this yet.
Breaking Change
Committed
Suggestion
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
Part of #19236
Code
const s1: string[] = ["x", 3, null as any];
const s2: string[] = ["x", 3];
Expected behavior:
s1should be an errors2should have an error span on3
Actual behavior:
s1is not an errors2has an error span ons2, which makes it impossible to figure out which element is wrong
Hypothesis: When checking a contextually-typed array literal, if an element type isn't assignable to the contextual type, issue an error on that element and return unknownType
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 two array-literal examples from the issue and inspect the compiler's contextual checking for array literal elements. Done means the first assignment is rejected and the second reports the error on the invalid element 3 rather than on s2.
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
- Mostly clear
- Newbie friendliness
- 35/100