Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Import Assertions (stage 3) #40694

Closed
5 tasks
Kingwl opened this issue Sep 22, 2020 · 15 comments · Fixed by #40698
Closed
5 tasks

Implement Import Assertions (stage 3) #40694

Kingwl opened this issue Sep 22, 2020 · 15 comments · Fixed by #40698
Assignees
Labels
ES Next New featurers for ECMAScript (a.k.a. ESNext) Fix Available A PR has been opened for this issue Needs Investigation This issue needs a team member to investigate its status. Rescheduled This issue was previously scheduled to an earlier milestone Suggestion An idea for TypeScript

Comments

@Kingwl
Copy link
Contributor

Kingwl commented Sep 22, 2020

Search Terms

esnext, import-assertions

Suggestion

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

Use Cases

Examples

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, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.
@Kingwl Kingwl changed the title Implement Import Assertions Implement Import Assertions (stage 3) Sep 22, 2020
@RyanCavanaugh RyanCavanaugh added the Needs Investigation This issue needs a team member to investigate its status. label Sep 22, 2020
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 4.2.0 milestone Sep 22, 2020
@DanielRosenwasser DanielRosenwasser added Suggestion An idea for TypeScript ES Next New featurers for ECMAScript (a.k.a. ESNext) labels Sep 22, 2020
@justinfagnani
Copy link

justinfagnani commented Sep 23, 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 .css file 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.

@kitsonk
Copy link
Contributor

kitsonk commented Sep 23, 2020

If 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.

@typescript-bot typescript-bot added the Fix Available A PR has been opened for this issue label Sep 23, 2020
@justinfagnani
Copy link

@kitsonk Please note I'm only talking about TypeScript syntax here. I'm well aware of the proposal and TC39's process.

@rbuckton
Copy link
Member

For 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.

/cc @DanielRosenwasser

@Kingwl
Copy link
Contributor Author

Kingwl commented Jan 27, 2021

https://github.com/tc39/proposal-json-modules is stage 3 too.

@RyanCavanaugh RyanCavanaugh added the Rescheduled This issue was previously scheduled to an earlier milestone label Mar 4, 2021
@Kingwl
Copy link
Contributor Author

Kingwl commented Mar 30, 2021

Nope.

@justinfagnani
Copy link

justinfagnani commented Jun 11, 2021

An update here: import assertions and JSON modules have shipped in Chrome and Edge 91. CSS Modules are up next.

@calebdwilliams
Copy link

I’m working on a Rollup plugin for this feature (afterwards will move in to Webpack), but each file that uses the assert syntax 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.

@Kingwl
Copy link
Contributor Author

Kingwl commented Jul 5, 2021

Sadly 4.4 has already released. We cannot add new syntax features after beta.

@justinfagnani
Copy link

@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.

@Kingwl
Copy link
Contributor Author

Kingwl commented Aug 16, 2021

any chance for 4.5?

As with 4.2, 4.3 and 4.4. No.

@IanVS
Copy link

IanVS commented Sep 9, 2021

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?

@Kingwl
Copy link
Contributor Author

Kingwl commented Sep 10, 2021

Oh, sorry. I misread chance as change.

@justinfagnani
Copy link

@Kingwl @rbuckton since #40698 is closing this issue, should we open another for ambient module definitions?

It think adding asserts to declare module is 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'}

@haoqunjiang
Copy link

FYI I opened a follow-up issue at #46135

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ES Next New featurers for ECMAScript (a.k.a. ESNext) Fix Available A PR has been opened for this issue Needs Investigation This issue needs a team member to investigate its status. Rescheduled This issue was previously scheduled to an earlier milestone Suggestion An idea for TypeScript
Projects
None yet
Development

Successfully merging a pull request may close this issue.