From d259fcb43c554411346f3bab6d1a5bcdf8aea5fc Mon Sep 17 00:00:00 2001 From: zhongsp Date: Fri, 29 Mar 2024 14:08:33 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A3=80=E6=9F=A5=E5=AF=BC=E5=85=A5=E5=B1=9E?= =?UTF-8?q?=E6=80=A7=E5=92=8C=E6=96=AD=E8=A8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zh/release-notes/typescript-5.4.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/zh/release-notes/typescript-5.4.md b/zh/release-notes/typescript-5.4.md index 629e0dce..13fcd4e0 100644 --- a/zh/release-notes/typescript-5.4.md +++ b/zh/release-notes/typescript-5.4.md @@ -284,3 +284,26 @@ var bar = require('some-package/bar'); TypeScript 会将路径解析为 `[...]/some-package/esm/foo-from-import.mjs` 和 `[...]/some-package/cjs/bar-from-require.cjs`。 更多详情请参考 [PR](https://github.com/microsoft/TypeScript/pull/56785)。 + +## 检查导入属性和断言 + +导入属性和断言现在会与全局的 `ImportAttributes` 类型进行检查。 +这意味着运行时现在可以更准确地描述导入属性。 + +```ts +// In some global file. +interface ImportAttributes { + type: "json"; +} + +// In some other module +import * as ns from "foo" with { type: "not-json" }; +// ~~~~~~~~~~ +// error! +// +// Type '{ type: "not-json"; }' is not assignable to type 'ImportAttributes'. +// Types of property 'type' are incompatible. +// Type '"not-json"' is not assignable to type '"json"'. +``` + +感谢 [Oleksandr Tarasiuk](https://github.com/a-tarasyuk)的 [PR](https://github.com/microsoft/TypeScript/pull/56034)。