From 6b12be99f2fa515021f74ddcc811098ee6d8e299 Mon Sep 17 00:00:00 2001 From: zhongsp Date: Sun, 11 Aug 2024 17:11:35 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=82=E8=80=83=20package.json=20=E4=B8=AD?= =?UTF-8?q?=E7=9A=84=E4=BE=9D=E8=B5=96=E9=A1=B9=E6=9D=A5=E7=94=9F=E6=88=90?= =?UTF-8?q?=E5=A3=B0=E6=98=8E=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 5.5 --- zh/release-notes/typescript-5.5.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/zh/release-notes/typescript-5.5.md b/zh/release-notes/typescript-5.5.md index 27c2ca28..9dd43a57 100644 --- a/zh/release-notes/typescript-5.5.md +++ b/zh/release-notes/typescript-5.5.md @@ -680,3 +680,21 @@ Titian 在推动独立声明实现方面发挥了关键作用,并在之前的 如果您打算使一个 `tsconfig.json` 文件可继承,请考虑是否应该用 `${configDir}` 替代 `./`。 更多详情请参考 [设计](https://github.com/microsoft/TypeScript/issues/57485) 和 [PR](https://github.com/microsoft/TypeScript/pull/58042)。 + +## 参考 package.json 中的依赖项来生成声明文件 + +之前,TypeScript 可能经常抛出如下错误: + +```txt +The inferred type of "X" cannot be named without a reference to "Y". This is likely not portable. A type annotation is necessary. +``` + +这通常是由于 TypeScript 的声明文件生成在从未在程序中显式导入的文件内容中发现自身。 +如果路径最终变成相对路径,生成对这样的文件的导入可能存在风险。 +然而,在 `package.json` 的依赖项(或 `peerDependencies` 和 `optionalDependencies`)中具有明确依赖关系的代码库中,在某些解析模式下生成这样的导入应该是安全的。 +因此,在 TypeScript 5.5 中,当出现这种情况时,我们更加宽松,许多此类错误应该消失。 + + +更多详情请参考 [PR](https://github.com/microsoft/TypeScript/issues/42873)。 + +