microsoft / microsoft/TypeScript
strictNullChecks not recognizing evaluated key in object
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
TypeScript Version: 2.3.2
Code
This version errors with strictNullChecks
export interface Opts {
params?: { [s: string]: string };
}
let token;
let options: Opts = { params: {} };
if (token) {
options.params["access_token"] = token;
}
This version does not error with strictNullChecks
export interface Opts {
params?: { [s: string]: string };
}
let token;
let options: Opts = {};
options.params = {};
if (token) {
options.params["access_token"] = token;
}
Expected behavior:
TS should recognize that params has been set in the object like it already does using a differently formatted method of initializing the variable.
Actual behavior:
TS fails to recognize that params has been set.
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 both TypeScript 2.3.2 snippets with strictNullChecks enabled and compare their control-flow analysis of the optional params property. Trace the strictNullChecks type-checking entry point that handles property assignments and indexed access. Done means the object-literal initialization form recognizes params as assigned consistently with the separately assigned form.
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