microsoft / microsoft/TypeScript
Cannot annotate a field in constructor as null using jsdoc @type
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
TypeScript Version: 4.0.2
Search Terms: jsdoc null type implicit any
Code
class Foo {
constructor () {
/** @type {number} */
this.bar = 42
/** @type {null} */
this.foo = null
}
}
Expected behavior:
Expected to have a class with two fields, bar of type number & foo of type null
I don't know why it doesn't understand null; using string | null works fine.
Actual behavior: Member 'foo' implicitly has an 'any' type.
Related Issues:
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 JavaScript example in the linked TypeScript Playground, comparing the @type {null} field with the working string | null form. Trace how JSDoc @type annotations are handled for constructor-assigned class fields; done means the null field is inferred as null rather than producing an implicit-any error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100