microsoft / microsoft/TypeScript
"Unassigned parameter" analysis doesn't account for local var declarations
Open
Nobody has claimed this yet.
Bug
Domain: check: Control Flow
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.4k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
In JS, it's legal to have a var declaration merge with a parameter declaration. By doing this and creating one with an initializer, you can get around TypeScript 4.4's "is this parameter ever assigned to?" checks for aliased conditions.
function foo(x: string | number) {
// Try uncommenting (1) and (2)
// (1)
// var x: string | number = 42;
// (2)
// x = 42;
const a = typeof x === "string";
if (a) {
x // observe the type switch between `string` and `never` here.
}
}
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 issue's foo example and compare the commented var x declaration with the direct assignment case. Trace the analysis that decides whether a parameter is ever assigned, then verify that a local var declaration with an initializer is accounted for without producing the incorrect narrowing shown in the example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100