microsoft / microsoft/TypeScript

Wrong import attribute typed as any, but should be typed as string

未关闭
#61,469 5 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

Domain: ES Modules Help Wanted Possible Improvement
主要语言
Go
星标
111k
派生
14.3k
平均合并
2 天 4 小时
30 天内合并 PR
132

描述

### 🔎 Search Terms

According to the [documentation at MDN for Import attributes](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import/with), the attribute value ie. [dataN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import/with#datan) is of type`string`.

In my VSCode setup using Typescript 5.8.2, this is typed as `any` in my .ts file:

Image

My tsconfig is as follows:

```
{
"exclude": ["dist"],
"compilerOptions": {
"jsx": "react",
"target": "ES2022",
"module": "esnext",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"moduleResolution": "node",
"strict": true,
"skipLibCheck": true,
"noImplicitAny": true,
"isolatedModules": false
}
}
```

### 🕗 Version & Regression Information

- This changed between versions ______ and _______
- This changed in commit or PR _______
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about _________
- I was unable to test this on prior versions because _______

### ⏯ Playground Link

_No response_

### 💻 Code

```ts
// Your code here
```

### 🙁 Actual behavior

Import attribute is typed as any instead of string.

### 🙂 Expected behavior

Import attribute should be typed as string.

### Additional information about the issue

_No response_

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

未指定源文件、测试或 playground。使用带有 import attribute 的 TypeScript 5.8.2 复现该行为,并检查编译器针对属性值的类型处理路径。完成的标准是该值被推断为 string 而不是 any,并且针对所报告案例具有回归覆盖。

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

评估

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

把新 issue 发到你的邮箱

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