microsoft / microsoft/TypeScript

typescript version 7 complains about unused generic type even though version 6 does not

Open
#64,308 2 comments 0 reactions 0 assignees View on GitHub
Working as Intended
Dominant language
Go
Stars
111k
Forks
14.3k
PR merge metrics
PR metrics pending

Description

### 🔎 Search Terms

"TS6196", "is declared but never used", "unused generic", "noUnusedParameters"

### 🕗 Version & Regression Information

- This changed between versions 6.0.3 and 7.0.2

### ⏯ Playground Link

https://www.typescriptlang.org/play/?#code/C4TwDgpgBAShBmAeAKgPigXigbwFAEgA3AQwBsBXCALimQBpcBfXXecgOwGNgBLAe3ZROAJwjFgEOEnoBVKBAAeE9gBMAzlEJ8eK1AAoSFapu0qAlDSkpUAblYdu-QSLESraA2Uo1kF2Ams7Ni5eASFRcUkAj0NvWj93dDx8UWByYUFkoi8IBnxGO2ZcTgE1YChReABGTHDXKPg9MzsS9jU+UggAOlI+AHM9Sqrm4tLyyoAmWpdIq3ZyAFsAIwhhOhMdfRHW9s6e-sGECe2xioQAZmmItwD55dX9KvOTto7u3oHK57sgA

### 💻 Code

```ts
type Ref = {
value: T,
}

function createRef(value: void): Ref;
function createRef(value: T): Ref;
function createRef(value: T): Ref {
return {
value,
};
}

const ref1 = createRef();
console.log(ref1);
const ref2 = createRef();
console.log(ref2);
const ref3 = createRef(13);
console.log(ref3);
```

### 🙁 Actual behavior

The typescript compiler version 7 fails with following error message:

```
code.ts:5:22 - error TS6196: 'U' is declared but never used.

5 function createRef(value: void): Ref;
~~~~~~~~~~~~~~

Found 1 error in code.ts:5
```

The typescript compiler version 6 succeeds without any errors.

### 🙂 Expected behavior

The typescript compiler version 7 should behave exactly like version 6 i.e. not fail.

### Additional information about the issue

This error only occurs with `noUnusedParameters` set to `true`.

Contributor guide

Open the contributing guide

Research direction

Reproduce the error from the linked Playground using noUnusedParameters and the shown createRef overloads, then trace the compiler’s handling of unused generic type parameters in overload declarations. Add a regression test covering the version-7 behavior and verify that the example no longer reports TS6196 while other unused-parameter diagnostics remain correct.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.