microsoft / microsoft/TypeScript
Issues with JSDoc private and protected
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Go
- Estrellas
- 111k
- Forks
- 14.3k
- Merge medio
- 2 d 4 h
- PR fusionados (30 d)
- 132
Descripción
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.
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza con la reproducción proporcionada de TypeScript Playground y compara el constructor heredado, las declaraciones de asignación y los casos de @this bajo checkJs. Rastrea el comportamiento del checker descrito en el informe, incluido el comportamiento contrastante de @readonly. Se considera terminado cuando el código proporcionado no produce errores y conserva las comprobaciones de acceso protected y private esperadas.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- javascript, typescript
- Área
- compilers
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bien especificado
- Aptitud para principiantes
- 38/100