-
Notifications
You must be signed in to change notification settings - Fork 449
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
Feature request: customize removal of extension on es6 imports to better support TypeScript/deno environments #6003
Comments
This is what happens if you add the extension: import {make as makeNotChecked} from './hookExample.tsx'; then run
|
Looks like this extension enforcement was a constraint in TypeScript but no longer as of a month ago: |
We can't assume people have the latest TS, and have configured it in that specific way. |
You’re right, we can’t. But we can assume that deno users are using that configuration. The current configuration breaks deno usage completely. I’m not asking for a new default, but that this behavior be configurable. |
I'd like to learn more about that. @genType.import("./hookExample.tsx")
@react.component
external make: (
... and produces an import to `.tsx. I guess you're referring to other examples. |
Adding a module resolution mode may be reasonable. TypeScript requires different extensions depending on the https://www.typescriptlang.org/tsconfig#moduleResolution
|
What's a concrete proposal for module resolution mode? How would the setting look like and what would the effect be? |
Usually the setting is only needed in Some given code like: @genType
let makeOther: () => Other.t = { ... } would generate like this: import * as Module_BS__Es6Import from './Module.bs';
import type {t as Other_t} from './Other.gen'; Assuming this follows the default settings: {
"gentypeconfig": {
"moduleResolution": "node" // default, identical to current behavior and TypeScript's default.
}
} (Option names intentionally follows the naming convention of In a TypeScript project with the same setup, this works well. If user changes the setting to: {
"gentypeconfig": {
"moduleResolution": "node16"
}
} should generates: import * as Module_BS__Es6Import from './Module.bs.js'; // extension required for ESM compatibility
import type {t as Other_t} from './Other.gen.js'; // extension here should follows the TS output's and {
"gentypeconfig": {
"moduleResolution": "bundler"
}
} should generates: import * as Module_BS__Es6Import from './Module.bs.js';
import type {t as Other_t} from './Other.gen.ts'; // TS extension for most bundlers, Deno, Bun, etc |
Does one of these names "bundler" etc indicate a specific extension? Is it better to specify by name or by extension? |
In general, this should be pretty easy to add. |
PRs accepted. This could be a good opportunity to check that the genType code is easy to modify. And if not, clean up parts of it in the process based on feedback. Generally, it should be quite approachable. |
IMO it's easy to understand when matched with the tsconfig. Since It is intended for interoperability with the TypeScript projects. Emitting with full extension is enough for JS/Flow. And user can customize it's own resolution for Flow by the flowconfig anyway. |
If tsconfig uses those names then it's perfect. |
Oh, I didn't notice that. bit sad to me 🥲 |
There are some rescript+flow users still, but those we know about have not updated the compiler version in several years, so they should not be affected. |
Looks like gentype only supports
.bs.js
extension but then proceeds to remove the.js
in the import statements.Examples missing extension:
https://github.com/rescript-lang/rescript-compiler/blob/457aeff9948c40fee5fc47df6e431152bd65d869/jscomp/gentype_tests/typescript-react-example/src/JSXV4.gen.tsx#L5
This behavior relies on non-standard import behavior. According to MDN ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#module-name ) ,
If the
.js
isn't removed, the TS code and JS code could be compatible with Deno and potentially other bundlers/environments.Looks like this behavior is also present in the main compiler and on every
.bs.js
file. Wonder if the community would consider this change interesting/useful to open up to more environments perhaps like Deno or Bun etc.Related to #4965 #5530
The text was updated successfully, but these errors were encountered: