Microsoft/TypeScript

ImportType attributes can include JS expressions

Open

#62,179 创建于 2025年8月3日

在 GitHub 查看
 (1 评论) (1 反应) (0 负责人)TypeScript (6,726 fork)batch import
BugDomain: ES ModulesHelp Wanted

仓库指标

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

描述

🔎 Search Terms

importtype, import type parsing

🕗 Version & Regression Information

  • This changed between versions 4.6.4 and 4.7.4 (with the old assert keyword)

⏯ Playground Link

https://www.typescriptlang.org/play/?ts=6.0.0-dev.20250802#code/CYUwxgNghgTiAEBbA9sArhBAiA7lALlgNwBQ+AngA4ID68AvPBdcgGbwCWilyM+AFLgJYANPADeJePCgBnWSD4AuCVOkyV-fgEoGAPlXr1YZADtZyTADoIyAOaCcAC3LwwUU-HLI08HDA58BAArWXgnRRAAfhiorG1SIwBfbR0RNSSSFNIgA

💻 Code

declare module "wat";
type _ = typeof import("wat", {
  assert: {
    a: (() => {
      console.log("why can you write js here????");
    })(),
  }
});

🙁 Actual behavior

parser accepts arbitrary JS expressions inside a type expression

🙂 Expected behavior

parser only allows string literal values or arbitrary type values

Additional information about the issue

No response

贡献者指南