Skip to content

Interoperability with Webpack import statements #38094

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

Open
slavafomin opened this issue Apr 21, 2020 · 1 comment
Open

Interoperability with Webpack import statements #38094

slavafomin opened this issue Apr 21, 2020 · 1 comment
Labels
Needs Proposal This issue needs a plan that clarifies the finer details of how it could be implemented. Suggestion An idea for TypeScript

Comments

@slavafomin
Copy link

slavafomin commented Apr 21, 2020

Hello!

First of all, thank you for your hard and amazing work.

The thing is, that Webpack supports more complex import statements than the standard. For example it defines "query" part of the import statements, which looks like this:

import { something } from './path/to/module?query';

The ./path/to/module is an actual filesystem path to a referenced module, however, the ?query is a query part. It allows to configure different loaders for different queries, so the same module could be treated differently in different import statements.

For example import component from './component'; would import the default symbol from the ./component module normally, however, import component from './component?raw'; could be used to load the source code of the ./component file as a string and would put it into component variable (this must be configured in Webpack config). This allows to perform very powerful operations on various files and add it to the resulting bundle. We are using it to generate documentation for example.

The problem is that TypeScript doesn't understand these "extended" import statements and shows errors during type checking. We have to either put @ts-ignore on top of such imports or to use paths configuration option to redirect the compiler to a file containing, e.g.: export default '';.

If TypeScript would support interoperability with extended Webpack import statements it would be very useful in complex projects.

By the way, besides "queries", Webpack also allows to specify loaders inline.

What do you think?

@DanielRosenwasser
Copy link
Member

Seems related to #10988

@RyanCavanaugh RyanCavanaugh added Needs Proposal This issue needs a plan that clarifies the finer details of how it could be implemented. Suggestion An idea for TypeScript labels Jun 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Proposal This issue needs a plan that clarifies the finer details of how it could be implemented. Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

3 participants