Skip to content
IJK

TypeScript 7.1 Beta: Import Attributes in Ambient Declarations

By IJK ·

What the TypeScript 7.1 Beta announcement says changes for ambient module declarations, what is not validated and where it recommends the declarations live.

What the beta adds

But a major issue is that runtime environments may support different import attributes entirely, and may act differently depending on whether they’re present. [1]

That’s why TypeScript 7.1 introduces support for import attributes in ambient module declarations. [2]

Ambient module declarationcan now name import attributesErrorwhen a required attribute is left offNot validated against files on diskfailed lookups surface at runtime or build
What does the beta let a declaration require, and what is not checked?

What it does not check

Note that imports matching these declarations are not validated against files on disk. [3]

As is currently the behavior when an import matches an ambient module declaration, failed lookups will be reported at runtime or during a bundler’s build process. [4]

We recommend libraries not include them in their published packages, and end-users will need to declare them in their own projects if necessary. [5]

Source imports and the new API

You must have an appropriate --module setting (i.e. esnext, nodenext, or preserve) to use source imports, as well as the appropriate esnext option in --lib or --target. [6]

When using import source, every imported module has the type AbstractModuleSource, a new global type in lib.esnext.d.ts. [7]

TypeScript 7.1 ships a new API that allows building powerful tools and utilities using our syntactic and semantic analyses. [8]

Rather than exposing a monolithic API, TypeScript 7.1 is organized into several entry points, each serving a specific purpose. [9]

Sources

  1. The TypeScript source says: But a major issue is that runtime environments may support different import attributes entirely, and may act differently depending on whether they’re present. Announcing TypeScript 7.1 Beta
  2. The TypeScript source says: That’s why TypeScript 7.1 introduces support for import attributes in ambient module declarations. Announcing TypeScript 7.1 Beta
  3. The TypeScript source says: Note that imports matching these declarations are not validated against files on disk. Announcing TypeScript 7.1 Beta
  4. The TypeScript source says: As is currently the behavior when an import matches an ambient module declaration, failed lookups will be reported at runtime or during a bundler’s build process. Announcing TypeScript 7.1 Beta
  5. The TypeScript source says: We recommend libraries not include them in their published packages, and end-users will need to declare them in their own projects if necessary. Announcing TypeScript 7.1 Beta
  6. The TypeScript source says: You must have an appropriate --module setting (i.e. esnext, nodenext, or preserve) to use source imports, as well as the appropriate esnext option in --lib or --target. Announcing TypeScript 7.1 Beta
  7. The TypeScript source says: When using import source, every imported module has the type AbstractModuleSource, a new global type in lib.esnext.d.ts. Announcing TypeScript 7.1 Beta
  8. The TypeScript source says: TypeScript 7.1 ships a new API that allows building powerful tools and utilities using our syntactic and semantic analyses. Announcing TypeScript 7.1 Beta
  9. The TypeScript source says: Rather than exposing a monolithic API, TypeScript 7.1 is organized into several entry points, each serving a specific purpose. Announcing TypeScript 7.1 Beta

Editorial (AI-assisted; automatically checked, not human-reviewed). Each statement is linked to its source; check the source before relying on a detail.

  • typescript
  • modules
  • tooling
  • beta