microsoft / microsoft/TypeScript

Issues with JSDoc private and protected

Aperta
#42,237 0 commenti 2 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Bug Domain: JSDoc
Lingua principale
Go
Stelle
111k
Fork
14.3k
Merge medio
1g 19h
PR unite (30g)
117

Descrizione

Bug Report

🔎 Search Terms

JSDoc access modifier

🕗 Version & Regression Information
  • This changed in version v3.8 probably 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.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia con la riproduzione fornita di TypeScript Playground e confronta il costruttore legacy, le dichiarazioni di assegnazione e i casi @this con checkJs. Traccia il comportamento del checker descritto nel report, incluso il comportamento contrapposto di @readonly. Il lavoro è completato quando il codice fornito non produce errori e preserva i controlli di accesso protected e private previsti.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
javascript, typescript
Ambito
compilers
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
38/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.