Repository navigation
Implement Import Assertions (stage 3) #40694
Description
Activity
- changed the title
[-]Implement Import Assertions [/-][+]Implement Import Assertions (stage 3)[/+]on Sep 22, 2020 - addedNeeds InvestigationThis issue needs a team member to investigate its status.This issue needs a team member to investigate its status.
on Sep 22, 2020 - addedSuggestionAn idea for TypeScriptAn idea for TypeScriptES NextNew featurers for ECMAScript (a.k.a. ESNext)New featurers for ECMAScript (a.k.a. ESNext)
on Sep 22, 2020 One thing that would be great to include in the design here is a way for assertions to inform the module interface, similar to wildcard module declarations.
For instance, with CSS modules, you might match on the
.cssfile extension right now:declare module '*.css' { const stylesheet: CSSStyleSheet; export default stylesheet; }
but with CSS modules and import assertions, we'd want to match on the
type: 'css'assertion. Some completely made up syntax:declare module '*' assert {type: 'css'} { const stylesheet: CSSStyleSheet; export default stylesheet; }
And then include this declaration with the DOM typings when CSS modules are standardized.
Reacted by Dan Vanderkam, Caleb Williams, A. Matías Quezada, Jacob M-G Evans, I-Want-ToBelieve, Konstantin Vyatkin, Leon Adler and Petar TodorovIf you have comments about the design, much better to bring them up with TC39 in the proposal: https://github.com/tc39/proposal-import-assertions. This really isn't the forum to debate ECMAScript syntax semantics.
- addedFix AvailableA PR has been opened for this issueA PR has been opened for this issue
on Sep 23, 2020 Kitson Kelly (@kitsonk) Please note I'm only talking about TypeScript syntax here. I'm well aware of the proposal and TC39's process.
Reacted by Kagami Sascha Rosylight, Alexey Iskhakov, Dj, Magnus Markling and I-Want-ToBelieveFor the short term, we will likely parse (but not enforce) import assertions. As far as whether/how that syntax should be applied to ambient module declarations, that's something the team will need to discuss in a future design meeting.
Reacted by Sven Sauleau and Tyler Brostromhttps://github.com/tc39/proposal-json-modules is stage 3 too.
Reacted by Kagami Sascha Rosylight, Teppei Sato, Noriyuki Shinpuku, Dan Vanderkam, Tim Reichen, Isabella Skořepová, Dj, Michael Lowe, Steven, Caleb Williams and 1 more- addedRescheduledThis issue was previously scheduled to an earlier milestoneThis issue was previously scheduled to an earlier milestone
on Mar 4, 2021 2 remaining items
An update here: import assertions and JSON modules have shipped in Chrome and Edge 91. CSS Modules are up next.
Reacted by Steven, ZHAO Jin-Xiang, Carter Snook, Tyler Brostrom, Tim Reichen, Caleb Williams, Kirill Groshkov, I-Want-ToBelieve, mdh and Adrian Z.I’m working on a Rollup plugin for this feature (afterwards will move in to Webpack), but each file that uses the
assertsyntax is now throwing despite the fact that the functionality is working. Would love to see this prioritized so developers can feel confident using import assertions.Reacted by Wenlu WangSadly 4.4 has already released. We cannot add new syntax features after beta.
Wenlu Wang (@Kingwl) any chance for 4.5?
Another update: Chrome and Edge are shipping CSS module scripts in 93. You can try it in beta now.
Reacted by Caleb Williams, Jacob M-G Evans, Jan Potoms, ZHAO Jin-Xiang, Steven, Théo LUDWIG, Wenlu Wang, Tim Reichen and Francesco Pipitaany chance for 4.5?
As with 4.2, 4.3 and 4.4. No.
Reacted by Caleb Williams and Adrian Z.As with 4.2, 4.3 and 4.4. No.
It's in the 4.5 iteration plan, though. 😕
I'm just curious, what is the reason it won't be considered for 4.5?
Reacted by Caleb Williams, ZHAO Jin-Xiang and Julian SlomanOh, sorry. I misread chance as change.
Reacted by Andrew Branch, Ian VanSchooten and Kirill GroshkovReacted by Andrew BranchReacted by Andrew BranchWenlu Wang (@Kingwl) Ron Buckton (@rbuckton) since #40698 is closing this issue, should we open another for ambient module definitions?
It think adding asserts to
declare moduleis a pretty logical way to define how import assertions work.Ideally this would be in the DOM lib:
declare module '*' assert {type: 'css'} { const stylesheet: CSSStyleSheet; export default stylesheet; }
With something similar in the built-in lib for
assert {type: 'json'}Reacted by ZHAO Jin-Xiang, Tyler Brostrom, Wilco Kruijer, Kagami Sascha Rosylight, Roy Ivy III, Kirill Groshkov, Peter Lejeck, Konstantin Vyatkin, Brandon Bennett and mdhFYI I opened a follow-up issue at #46135
Reacted by Justin Fagnani
Search Terms
esnext, import-assertions
Suggestion
https://github.com/tc39/proposal-import-assertions
Use Cases
Examples
Checklist
My suggestion meets these guidelines: