Skip to content

Fix Type Declarations for ESModule#18

Merged
ym-project merged 6 commits into
ym-project:v0from
neurolag:v0
Dec 7, 2022
Merged

Fix Type Declarations for ESModule#18
ym-project merged 6 commits into
ym-project:v0from
neurolag:v0

Conversation

@neurolag

@neurolag neurolag commented Dec 1, 2022

Copy link
Copy Markdown
Contributor

Changes made in this PR will add type declarations for the ESModule version of this package.
In doing so, this PR will fix #17.

@ym-project

ym-project commented Dec 7, 2022

Copy link
Copy Markdown
Owner

Look. We have problems with index.d.mts file.
When we use inside mjs file this code snippet:

import gulpEsbuild, {createGulpEsbuild} from "gulp-esbuild";

console.log(gulpEsbuild);
console.log(createGulpEsbuild);
console.log(gulpEsbuild.createGulpEsbuild);

import("gulp-esbuild")
	.then(result => {
		console.log('dynamic import');
		console.log(result.createGulpEsbuild);
		console.log(result.default);
		console.log(result.default.createGulpEsbuild);
	})

Typescript uses index.d.mts and shows us, what out package has gulpEsbuild.createGulpEsbuild. But actually it is not the truth.

[Function: plugin]
[Function: createGulpEsbuild]
undefined
dynamic import
[Function: createGulpEsbuild]
[Function: plugin]
undefined

Should mts declaration file have import from index.js file? I think no.

@ym-project

Copy link
Copy Markdown
Owner

I mean mts declaration file should looks like:

import {Transform} from 'stream'
import {BuildOptions} from 'esbuild'

type Options = Omit<
	BuildOptions,
	'write' | 'incremental' | 'entryPoints' | 'stdin' | 'watch' | 'allowOverwrite' | 'absWorkingDir' | 'nodePaths'
> & {
	metafileName?: string
}

interface CreateOptions {
	incremental?: boolean
	pipe?: boolean
}

type GulpEsbuild = (options: Options) => Transform
type CreateGulpEsbuild = (options: CreateOptions) => GulpEsbuild

declare const gulpEsbuild: GulpEsbuild;
declare const createGulpEsbuild: CreateGulpEsbuild

export {createGulpEsbuild}
export default gulpEsbuild

Without & from d.ts

@neurolag

neurolag commented Dec 7, 2022

Copy link
Copy Markdown
Contributor Author

Thanks, I totally missed that one
I'll fix it asap

@neurolag

neurolag commented Dec 7, 2022

Copy link
Copy Markdown
Contributor Author

Alright! Fixed it now.
Sorry for the inconvenience

@ym-project ym-project merged commit 8a48fd3 into ym-project:v0 Dec 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Type Declarations not Working for ESModule

2 participants