Skip to content

Import Attributes (Stage 3)Β #53656

Closed
@mkubilayk

Description

@mkubilayk

Suggestion

πŸ” Search Terms

import attributes, import assertions, esnext

βœ… Viability Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

⭐ Suggestion

https://github.com/tc39/proposal-import-attributes

In January 2023, Import Assertions proposal was demoted back to Stage 2 to investigate a solution for the web platform's needs. In March 2023, the proposal was renamed to Import Attributes and moved back to Stage 3 (with conditional consensus - pending spec text review).

TypeScript should support the new syntax. The most relevant change for TypeScript is that the keyword changed from assert to with.

import json from "./foo.json" with { type: "json" };

import("foo.json", { with: { type: "json" } });

export { val } from './foo.js' with { type: "javascript" };

The minimal option here is just to add the with syntax. Ideally there would also be two enhancements:

  • Deprecating assert: For compatibility with existing implementations, the assert keyword is still allowed by the spec until it's safe to remove it. Chrome will explore removing it. Babel is deprecating the syntax with a plan to eventually remove it in Babel 8. TypeScript could follow something similar to the 5-release deprecation process by initially suggesting migration via warnings and quick fixes - though we recognise that the deprecation process was originally intended only for flags.
  • Auto-complete for static import/re-export declarations: Auto-complete seems to be only working with dynamic import() right now. This could be expanded to also work for attributes in static declarations.

πŸ“ƒ Motivating Example

This will be new ECMAScript syntax so motivation is to be compatible with the language. The champion group considers this to be stable, even though it just changed: this is what re-promoting to Stage 3 represents.

It sounds like this would also unblock #49055 (comment).

πŸ’» Use Cases

https://github.com/tc39/proposal-import-attributes#motivation

In addition, we have an internal use case in Bloomberg to use Import Attributes as an annotation to achieve lazy-loading by deferring module evaluation. This is an early implementation of the TC39 proposal for Deferring Module Evaluation.


This issue is raised only for awareness. At this point we are not planning to implement.

Metadata

Metadata

Assignees

Labels

CommittedThe team has roadmapped this issueFix AvailableA PR has been opened for this issueSuggestionAn idea for TypeScript

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions