microsoft / microsoft/TypeScript

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

Open
#63,754 4 comments 0 reactions 0 assignees View on GitHub
Bug
Dominant language
Go
Stars
111k
Forks
14.3k
PR merge metrics
PR metrics pending

Description

### 🔎 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_

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the diagnostic with types.ts and code.js using the reported TypeScript 7.0.2 and the earlier 7.0.0-dev.260707.2 version. Trace how the JSDoc @type reference to Example['method'] is resolved and why | undefined is added. Done means the valid method type no longer produces diagnostic 8030, with regression coverage for this example.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.