-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
import './file.json'
: This module is declared with using 'export ='
#37623
Comments
I also tried: import * as list from './list.json; While that works, it shouldn't. |
What module loaders present JSON objects via the default export instead of top-level export? Or does the file look like
? |
I had to do some research:
Ultimately, I think that TypeScript’s behavior is correct since The right flag to enable support (at the moment) seems to be |
Since both Webpack and node import without the It's very sad that we have to stick with target=es5 in order to profit from the auto completion support for imported json files when using webpack. |
In ECMAScript, importing JSON will be implemented with JSON modules (stage 2) based on Import Assertions (stage 3). import json from "./foo.json" assert { type: "json" };
import("foo.json", { assert: { type: "json" } }); In TypeScript: Implement Import Assertions (stage 3) · Issue #40694 · microsoft/TypeScript |
In short, JSON files's implied type definition is always defined via
export =
, even if I'm usingmodule: es2015
, causing it to error unless I use an unnecessary flag (allowSyntheticDefaultImports
)TypeScript Version: 3.9.0-dev.20200326
Search Terms:
import require json module commonjs es2015
Code
Expected behavior:
list
is of typestring[]
Actual behavior:
Workaround:
allowSyntheticDefaultImports: true
works as expected, but that flag is unsafe and I don't want (need) to use it.Playground Link: repro.zip
Related Issues: #15146
The text was updated successfully, but these errors were encountered: