Skip to content

Commit 6b12be9

Browse files
committed
参考 package.json 中的依赖项来生成声明文件
5.5
1 parent c4036e2 commit 6b12be9

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

zh/release-notes/typescript-5.5.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,3 +680,21 @@ Titian 在推动独立声明实现方面发挥了关键作用,并在之前的
680680
如果您打算使一个 `tsconfig.json` 文件可继承,请考虑是否应该用 `${configDir}` 替代 `./`
681681

682682
更多详情请参考 [设计](https://github.com/microsoft/TypeScript/issues/57485)[PR](https://github.com/microsoft/TypeScript/pull/58042)
683+
684+
## 参考 package.json 中的依赖项来生成声明文件
685+
686+
之前,TypeScript 可能经常抛出如下错误:
687+
688+
```txt
689+
The inferred type of "X" cannot be named without a reference to "Y". This is likely not portable. A type annotation is necessary.
690+
```
691+
692+
这通常是由于 TypeScript 的声明文件生成在从未在程序中显式导入的文件内容中发现自身。
693+
如果路径最终变成相对路径,生成对这样的文件的导入可能存在风险。
694+
然而,在 `package.json` 的依赖项(或 `peerDependencies``optionalDependencies`)中具有明确依赖关系的代码库中,在某些解析模式下生成这样的导入应该是安全的。
695+
因此,在 TypeScript 5.5 中,当出现这种情况时,我们更加宽松,许多此类错误应该消失。
696+
697+
698+
更多详情请参考 [PR](https://github.com/microsoft/TypeScript/issues/42873)
699+
700+

0 commit comments

Comments
 (0)