microsoft / microsoft/TypeScript
JavaScript class property becomes `any` without warning when used in a function that is assigned to itself
Open
Nobody has claimed this yet.
Awaiting More Feedback
Suggestion
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.4k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
🔎 Search Terms
jsdoc class null any
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about
any
⏯ Playground Link
💻 Code
export class Foo {
/**
* @param {number?} maybeNum
*/
constructor(maybeNum) {
this.maybeNum = null;
this.setMaybeNum();
}
setMaybeNum() {
this.maybeNum = Math.max(this.maybeNum);
}
/**
* @param {string} str
*/
takesString(str) {}
foo() {
this.takesString(this.maybeNum);
// ^^^^^^^^^^^^^---- no error, maybeNum is any
}
}
🙁 Actual behavior
this.maybeNum is any
🙂 Expected behavior
this.maybeNum is number | null or (since noImplicitAny is set) an error is emitted warning the user that this.maybeNum is any.
Additional information about the issue
It seems like the core issue here is this line:
this.maybeNum = Math.max(this.maybeNum);
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 linked TypeScript Playground example and the assignment this.maybeNum = Math.max(this.maybeNum) in the JavaScript class. Trace how that assignment affects the later takesString(this.maybeNum) call, then verify the fix against the expected number | null type or a noImplicitAny diagnostic.
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
- Clearly specified
- Newbie friendliness
- 35/100