microsoft / microsoft/TypeScript
JavaScript class property becomes `any` without warning when used in a function that is assigned to itself
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.4k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
🔎 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);
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginnen Sie mit dem verknüpften TypeScript Playground-Beispiel und der Zuweisung this.maybeNum = Math.max(this.maybeNum) in der JavaScript-Klasse. Verfolgen Sie, wie sich diese Zuweisung auf den späteren Aufruf takesString(this.maybeNum) auswirkt, und überprüfen Sie anschließend die Korrektur anhand des erwarteten Typs number | null oder einer noImplicitAny-Diagnose.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- javascript, typescript
- Bereich
- compilers
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Klar beschrieben
- Anfängerfreundlichkeit
- 35/100