You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ECMAScript now has stage-3 recognized type attributes on import statements.
// text has type `string`importtextfrom"./file.txt"with{"type": "text"}// bytes has type `Uint8Array`importbytesfrom"./file.whatever"with{"type": "bytes"}
Yeah, but you can just write multiple specific modules instead of using a union type. It's duplicative but it's fine.
Also, overrides? Unions would have allowed those.
declare module "*.foo"with{"my-thing": "a"|"b"}{/*base contents*/}declare module "*.foo"with{"my-thing": "a"}{/*overrides with more specific type for 'a'*/}// vs.declare module "*.foo"with{"my-thing": "a"}{/*base contents*/}declare module "*.foo"with{"my-thing": "b"}{/*base contents*/}// This is now a merge with the first declaration.declare module "*.foo"with{"my-thing": "a"}{/*overrides(?) with more specific type for 'a'*/}
But lots of problems that can come up with "most specific" lookup.
Like what?
Part of it is now like overload resolution
Hard to diagnose which one is chosen (or not chosen).
Also, can mix poorly when types have differing IDs, working with parallel independent checkers.
Conclusions:
7.1 will have unit-only types, no override behavior for declare module.
This PR will not contain lib.d.ts updates, and they may not ship as part of 7.1.
Future: revisit the above, plus a flag to make sure that the existence of relative file paths are actually checked when they hit a pattern.
Something Bartek Iwańczuk (@bartlomieju) raised afterwards was that the current semantics of prioritizing standard resolutions over type attributes means that we'll resolve the wrong types for sourceText in the following code.
importsourceTextfrom"./a.js"with{type: "text"};
Gabriela Araujo Britto (@gabritto) and I chatted, and while it's very rare that you'd want an alternative import type from a recognized file type, we'd like to align with the spec.
It does feel like { type: "css" } on an import is a good indicator of what you want, but Andrew Branch (@andrewbranch) asked if the existence of a .d.css.ts implies a user wants a more specific module shape. More broadly, you can imagine an ambient module like
but generate more specific types at build time. That said, I have a hard time imagining that you'd want a type: ... for something your build tooling handles anyway. Maybe you just want a fallback for when a content mapper won't be active?
Import Attributes on Ambient Modules
#63931
ECMAScript now has stage-3 recognized
typeattributes on import statements.Spec explicitly will allow these, but environments are free to add their own.
type: "css".Last discussed Design Meeting Notes, 9/26/2025 #62615
So Support import attributes on ambient modules #63931 adds support for import attributes in ambient modules.
Idea is that these patterns are actually limited type specifications.
We match specifiers against patterns and get the most specific patterns and attribute types.
Is the idea that
lib.esnext.d.tsandlib.dom.d.tswill have the above import attributes?lib.dom.d.tsbrought into Node.js context - pretty common unfortunately.type: "css".typepattern anyway.File existence?
File copying from inputs/outputs?
package.json).Merging conflicting declarations?
Why are these types more capable just allowing unit types?
Why allow
type: string?Because you might want union types, reduce code.
Also, overrides? Unions would have allowed those.
But lots of problems that can come up with "most specific" lookup.
Conclusions:
declare module.lib.d.tsupdates, and they may not ship as part of 7.1.