microsoft / microsoft/TypeScript
Issues with JSDoc private and protected
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.3k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
Bug Report
🔎 Search Terms
JSDoc access modifier
🕗 Version & Regression Information
- This changed in version
v3.8probably because JSDoc accessibility modifiers were introduced; that is to say: it never worked
⏯ Playground Link
Playground Link: Provided
💻 Code
/** @class */
function Legacy () {
/** @protected */
this.prop = 1; // should not be an error
this.doStuff(); // should not be an error
}
/** @private */
Legacy.prototype.doStuff = function () {
this.prop; // should not be an error
this.doStuff(); // should not be an error
}
class C {
/** @protected */
prop = 1;
}
/** @this {C} */
function fn() {
this.prop; // the equivalent works in TS
}
Compiler Options
{
"compilerOptions": {
"noImplicitAny": true,
"strictFunctionTypes": true,
"strictPropertyInitialization": true,
"strictBindCallApply": true,
"noImplicitThis": true,
"noImplicitReturns": true,
"alwaysStrict": true,
"esModuleInterop": true,
"checkJs": true,
"allowJs": true,
"declaration": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"moduleResolution": 2,
"target": "ES2017",
"jsx": "React",
"module": "ESNext"
}
}
🙁 Actual behavior
Using legacy class syntax and so-called "assignment declarations" don't recognize that the properties are actually accessed inside the class. That's because the checker logic only looks for real ClassLikeDeclaration Nodes.
Note that @readonly correctly recognizes function Legacy as the constructor and allows assignment there.
Using a protected member in a function with explicit this-parameter works in TS, but doesn't when using @this in JS.
🙂 Expected behavior
No errors in the code.
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
Beginne mit der bereitgestellten TypeScript Playground-Reproduktion und vergleiche den legacy constructor, assignment declarations und @this-Fälle unter checkJs. Verfolge das im Bericht beschriebene Checker-Verhalten, einschließlich des kontrastierenden @readonly-Verhaltens. Als erledigt gilt, wenn der bereitgestellte Code keine Fehler erzeugt und dabei die erwarteten protected- und private-Zugriffsprüfungen beibehält.
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
- 38/100