microsoft / microsoft/TypeScript

Diagnostic code 8030 being incorrectly generated using JSDoc `@type` on a function.

Aperta
#63,754 4 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Bug
Lingua principale
Go
Stelle
111k
Fork
14.3k
Merge medio
2g 4h
PR unite (30g)
132

Descrizione

### 🔎 Search Terms

Diagnostic 8030 is being generated incorrectly when using JSDoc `@type` on a method when the type is being referred to from an interface. This is using the new `tsc` LSP - version 7.0.2.

### 🕗 Version & Regression Information

- This changed between versions 7.0.0-dev.260707.2 and 7.0.2.
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about new native issues being transferred into the main typescript repo.

### ⏯ Playground Link

_No response_

### 💻 Code

```ts
// types.ts
interface Example {
method (): number;
}
export {};

// code.js
const exampleFns = {
/**
* @type {Example['method']} // A JSDoc `@type` tag on a function must have a signature with the correct number of arguments.
*/
method () {
return Math.random();
}
};
```

### 🙁 Actual behavior

in this example, the diagnostic and LSP info does not tell the user that typescript is internally suffixing `| undefined` to the type. As such wrapping the type in `NonNullable` removes the error diagnostic, I do not believe this to be intended behaviour as previous iterations the golang native LSP `tsgo` (7.0.0-dev.260707.2) did not produce this diagnostic, nor did previous versions of typescript.

### 🙂 Expected behavior

The type should be properly referenced with no additional suffixing of types, as it used to.

### Additional information about the issue

_No response_

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 riproducendo la diagnostica con types.ts e code.js usando la versione di TypeScript 7.0.2 indicata e la versione precedente 7.0.0-dev.260707.2. Traccia come viene risolto il riferimento JSDoc @type a Example['method'] e perché viene aggiunto | undefined. Il lavoro è completato quando il tipo di metodo valido non produce più la diagnostica 8030 e questo esempio dispone di una copertura di regressione.

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à
Attiva
Chiarezza
Abbastanza chiara
Idoneità per principianti
48/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.