microsoft / microsoft/TypeScript

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

未关闭
#64,308 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
Working as Intended
主要语言
Go
星标
111k
派生
14.3k
平均合并
2 天 4 小时
30 天内合并 PR
132

描述

### 🔎 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`.

贡献指南

打开贡献指南

调研方向

使用 noUnusedParameters 和所示的 createRef 重载复现链接 Playground 中的错误,然后跟踪编译器对重载声明中未使用的泛型类型参数的处理方式。添加一个覆盖 version-7 行为的回归测试,并验证示例不再报告 TS6196,同时其他未使用参数诊断仍然正确。

由索引模型根据 Issue 内容生成。

评估

技术栈
typescript
领域
compilers
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
活跃
描述清晰度
描述清楚
新手友好度
68/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。