microsoft / microsoft/TypeScript
Issues with JSDoc private and protected
Personne n'a encore pris cette issue.
- Langage dominant
- Go
- Étoiles
- 111k
- Forks
- 14.3k
- Merge moyen
- 2 j 4 h
- PR mergées (30 j)
- 132
Description
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.
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par la reproduction fournie dans TypeScript Playground et comparez le constructeur legacy, les déclarations d’affectation et les cas @this avec checkJs. Suivez le comportement du checker décrit dans le rapport, y compris le comportement contrasté de @readonly. C’est terminé lorsque le code fourni ne produit aucune erreur tout en conservant les vérifications d’accès protected et private attendues.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- javascript, typescript
- Domaine
- compilers
- Type d'issue
- Bug
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Activité
- À l'abandon
- Clarté
- Clairement spécifiée
- Accessibilité débutants
- 38/100