π Search Terms
import attributes, import assertions
β
Viability Checklist
β Suggestion
TypeScript 5.3 Beta supports the latest updates to the import attributes proposal, which is great to see!
It's possible to augment the global ImportAttributes type with host-specific attributes. However, auto-complete and type-checking of import attributes seems to only work with dynamic import(). It would be nice if this could also work for attributes in static declarations.
π Motivating Example
https://www.typescriptlang.org/play?target=99&ts=5.3.0-dev.20231002#code/CYUwxgNghgTiAEBzCB7ARlC8DeBYAUPPAJYB2ALiDAGZRgLwCSAtgA4ozkCC55MxaAK6UAzjgJEi5AJ6sQALngAiAFYiUpJRPgBfAnvwFibDuXgAqeFDGkx1GCmbLqKFEvgB3YuQAWOeDJyikqkKOQAtGoa7joA3AQAbijEwPC28Yb4xuycABRKLm4ANOKEnt4+inhlUrIKyqERUZraBjoAlBkEQA
declare global {
interface ImportAttributes {
type: "json";
}
}
import * as ns from "foo" with { type: "not-json" }; // no error
void ns;
import("foo", {
with: {
type: "not-json", // Type '"not-json"' is not assignable to type '"json"'. (2322)
},
});
π» Use Cases
- What do you want to use this for?
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 that annotates the static import.
It would be a better developer experience if auto-complete was available for Import Attributes in the static form.
- What shortcomings exist with current approaches?
It is possible to write a static import declaration using unknown/invalid attributes.
- What workarounds are you using in the meantime?
None.
π Search Terms
import attributes, import assertions
β Viability Checklist
β Suggestion
TypeScript 5.3 Beta supports the latest updates to the import attributes proposal, which is great to see!
It's possible to augment the global
ImportAttributestype with host-specific attributes. However, auto-complete and type-checking of import attributes seems to only work with dynamicimport(). It would be nice if this could also work for attributes in static declarations.π Motivating Example
https://www.typescriptlang.org/play?target=99&ts=5.3.0-dev.20231002#code/CYUwxgNghgTiAEBzCB7ARlC8DeBYAUPPAJYB2ALiDAGZRgLwCSAtgA4ozkCC55MxaAK6UAzjgJEi5AJ6sQALngAiAFYiUpJRPgBfAnvwFibDuXgAqeFDGkx1GCmbLqKFEvgB3YuQAWOeDJyikqkKOQAtGoa7joA3AQAbijEwPC28Yb4xuycABRKLm4ANOKEnt4+inhlUrIKyqERUZraBjoAlBkEQA
π» 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 that annotates the static import.
It would be a better developer experience if auto-complete was available for Import Attributes in the static form.
It is possible to write a static import declaration using unknown/invalid attributes.
None.