-
Notifications
You must be signed in to change notification settings - Fork 7
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
Type Declarations not Working for ESModule #17
Comments
Hello @manuth! Thank you for the issue! |
Sure - will do asap |
About This ErrorUsing ESModules in TypeScriptTypeScript allows you to emit modules both written as CommonJS or as ESM. The corresponding setting is called Files written in CommonJS can import ESModules using dynamic (await import("gulp-esbuild"))({}); Files written in ESM can import other ESModules using import statements: import gulpEsbuild from "gulp-esbuild";
gulpEsbuild({}); The
|
I tried your reproduction sequencing but I didn't face any types problems. What did I do wrong? |
It's nothing big, really You might want to add something like this to your {
"compilerOptions": {
"allowJs": true, // Allow JavaScript files to be part of your project
"checkJs": true, // Enable type checking in JavaScript files
/* With `outDir` unspecified, compiling a JavaScript file would cause it to overwrite itself.
* Adding this option will tell TypeScript that this project is not supposed to be compiled and
* thus not causing JavaScript files to overwrite themselves. */
"noEmit": true
}
} |
Oh sorry... I just noticed that I said to create an Sorry for the inconvenience. |
As I understand typescript documentation correctly, module resolution You can run command For
For
As you can see, typescript goes |
If we set
|
Yes but the You might notice the little differences in my PR Namely:
Line 330 in d169482
Line 331 in d169482
Lines 2 to 4 in 2fa6abe
While Lines 19 to 23 in d169482
|
Ok. I have understood. |
Awesome! Thank you so much for taking time 😄 |
When trying to import this package from an ESModule TypeScript ecosystem, it won't work.
TypeScript shows an error stating that the corresponding types could not be found.
This is caused by the
package.json
setting the file forimport
calls to beindex.mjs
.The setting mentioned before causes TypeScript to go search for the type declarations at
gulp-esbuild/index.d.mts
.There are basically two ways on how to fix this:
A separate
index.d.mts
file can be created or - if both type declarations match - the types can be set to resolve toindex.d.ts
:Sadly, the type declarations do not match (
index.js
uses an export assignment,index.mjs
uses a default export), so I think a separate type declaration file should be the proper solution.I'll go create a PR concerning this matter.
The text was updated successfully, but these errors were encountered: