-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Support TypeScript import = require
syntax
#1244
Comments
TypeScript's module system is broken unless synthetic imports and esModuleInterop are enabled. With these settings, I don't believe there's any use case for the |
In what way is TS’s module system broken without those options? I’ve never heard that before. |
For example, a common thing people do without those options is |
Ah, interesting. Still, since people still use TypeScript without |
I suppose that’s fair too. |
I wouldn't agree that typescript's module system is broken in terms of react. Whilst yes, react is built as a es6 module, and internally it has a default export of the React object [1], the package itself uses commonjs Which means that using React with synthetic default imports is technically wrong. [1] https://github.com/facebook/react/blob/master/packages/react/src/React.js#L109 |
@bradzacher React is a CJS module - which means it only has a default export. https://github.com/facebook/react/blob/master/packages/react/index.js#L16 ensures that the |
Ultimately it shows a weakness of using CJS to represent es6 modules. const exp = { a, b, c };
module.exports = exp;
// does this mean
export default exp;
// or
export { a, b, c }; The intent is definitely the former, but based on how the transpilation works, reality is the latter. |
… which means the intent is "correct" and the transpiler (tsc, in this case, with default settings) is broken. With a few settings (which I believe are synthetic imports and ES module interop) it behaves properly. (I wouldn't classify this as a weakness, more as, CJS only has default exports; ESM adds named exports. So, lacking a standard interop approach, the most "correct" thing is to treat a CJS module as having a single default export) |
Per import-js/eslint-plugin-import#1244, the `eslint/import` plug-in does not currently support the `import X = require(Y);` syntax, causing extraneous imports in this form to be ignored by the linter.
Per import-js/eslint-plugin-import#1244, the `eslint/import` plug-in does not currently support the `import X = require(Y);` syntax, causing extraneous imports in this form to be ignored by the linter.
I'm also waiting for this plugin to suport The module const assert = require("assert");
assert(true); // does not throw
assert(false); //does throw And here comes the clue: import assert = require("./MyAssert");
assert(true); This here is not: import * as assert from "./MyAssert";
import * as MyClass from "./MyClass";
assert(true);
new MyClass(); Because while So there certainly is a reason why Thanks for this great plugin ^^ |
@manuth that's not quite correct; if you use esModuleInterop and synthetic imports (as |
It is valid typescript code and therefore it would be quite nice if this plugin could handle it. That's all people commenting here were asking for. |
I totally agree, which is why i put the "help wanted" label on this issue. I'm saying that regardless, the best solution is to avoid using this syntax in the first place, and I wanted to correct your explanation about it. |
Thanks for your help then 😄 |
Note that import { foo } from "./bar.js";
import path = require("path");
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~ import/order: `path` import should occur before import of `./bar.js` import path = require("path");
import { foo } from "./bar.js";
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ import/first: Import in body of module; reorder to top. |
@ExE-Boss thanks for the report! a PR with a fix, or a PR with a failing test case, or an issue would be great (in that order ;-) ) :-D |
Currently this project only parses regular import statements as import statements. However, TypeScript also supports another syntax:
Would it be possible for the plugin to check these imports as well?
The text was updated successfully, but these errors were encountered: