microsoft / microsoft/TypeScript
In JS, there's no way to assert that a property is definitely assigned
Open
@sandersn is already working on this.
Since Apr 6, 2018.
Domain: JavaScript
Needs Proposal
Suggestion
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
Keywords: JSDoc, Salsa, JavaScript, definite, initialization, initialized, assigned, assertion
class ElementWrapper {
constructor() {
this.init();
}
init() {
this.element = document.createElement('div');
}
getElementStyle() {
this.element.style // error: element is possibly undefined
}
}
We need a way to convince TypeScript in strictNullChecks that this.element is initialized in getElementStyle. Basically a definite initialization assertion.
Related is #23405 which tracks non-null assertions on the expression level.
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.
Assessment
This issue has not been assessed yet.