Skip to content
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

fix: correct .d.cts default export type #458

Merged
merged 2 commits into from
Dec 28, 2024
Merged

fix: correct .d.cts default export type #458

merged 2 commits into from
Dec 28, 2024

Conversation

kricsleo
Copy link
Contributor

resolves #457

@kricsleo
Copy link
Contributor Author

I've tested against the ./example/1.zero-config and the output of utils.d.cts has changed from:

declare function sum(a: number, b: number): number;

export { sum as default };

to:

declare function sum(a: number, b: number): number;

export = sum;

This is the expected types in pair with the utils.cjs output:

'use strict';

function sum(a, b) {
  return a + b;
}

module.exports = sum;

@pi0 pi0 requested a review from danielroe December 27, 2024 12:35
@pi0 pi0 changed the title fix: fix the .d.cts default export type fix: correct .d.cts default export type Dec 27, 2024
Copy link
Member

@danielroe danielroe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks good to me!

an optimisation might be to use findExports from mlly rather than maintaining a separate regexp

@pi0 pi0 merged commit 6ac4def into unjs:main Dec 28, 2024
2 checks passed
@userquin
Copy link
Contributor

userquin commented Dec 29, 2024

Looks like we also need to include also this change for d.ts files for node10 module resolution: I'm updating unbuild to 3.2.0 in UnoCSS repo and d.ts files are wrong.

@danielroe
Copy link
Member

that would depend on whether it was type: module, i assume?

@userquin
Copy link
Contributor

yes, we also have some problems with CJS and node16, for example, postcss package exporting default and a type, this PR doesn't change it:

// d.cts
export { type UnoPostcssPluginOptions, unocss as default };

should be:

export = unocss;
export { type UnoPostcssPluginOptions };

imagen

@userquin
Copy link
Contributor

Even with type set to commonjs, unbuild generating wrong dts files, check #474, reproduction there

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.

The default export declaring in .d.cts is not accurate.
4 participants