Microsoft/TypeScript

Unexpected "'Type' is declared but its value is never read." error with jsdoc @import syntax

Open

#60,908 创建于 2025年1月2日

在 GitHub 查看
 (7 评论) (5 反应) (0 负责人)TypeScript (6,726 fork)batch import
BugDomain: JSDocFix AvailableHelp Wanted

仓库指标

Star
 (48,455 star)
PR 合并指标
 (平均合并 6天 17小时) (30 天内合并 9 个 PR)

描述

🔎 Search Terms

jsdoc @import "is declared but its value is never read"

🕗 Version & Regression Information

I have seen this error since the introduction of @import in jsdoc comments (TS 5.5 if i recall correctly)

⏯ Playground Link

No response

💻 Code

I made a testcase repo https://github.com/DavidBruant/jsdoc-import-unused-testcase It is as reduced as a managed to make it

The code :

/** @import {ImportedType} from './types.d.ts' */

function id() { return undefined }

/** @type {Set<ImportedType>} */
export const phases = new Set(['a', 'b'])

The types.d.ts file:

export type ImportedType = 'a' | 'b'

🙁 Actual behavior

tsc and VSCodium both say:

code.js:1:5 - error TS6133: 'ImportedType' is declared but its value is never read.

1 /** @import {ImportedType} from './types.d.ts' */

🙂 Expected behavior

There shouldn't be an error because of the line using the type : /** @type {Set<ImportedType>} */

We've had this error in plently of places. It also seems like it occurs more regulary when the type is used within a generics

Additional information about the issue

For some reason, removing function id() { return undefined } from the code solves the problem while it seems completely unrelated to the problem

贡献者指南