Skip to content

ImportType attributes can include JS expressionsΒ #62179

@easrng

Description

@easrng

πŸ”Ž 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: ES ModulesThe issue relates to import/export style module behaviorHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions