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
Change TypeScript definitions for ESM #7309
Conversation
Summary: - Rewrite TypeScript definitions to use ESM syntax, avoiding the specific syntax like `namespace`. - Update `tsconfig.json` for ESM and Node.js 18. - Remove no longer needed `test.d.ts`. - Add a patch for the `is-plain-object` package to avoid type-check errors. See also: - https://www.typescriptlang.org/tsconfig - https://devblogs.microsoft.com/typescript/announcing-typescript-4-7/#package-json-exports-imports-and-self-referencing - jonschlinkert/is-plain-object#28
🦋 Changeset detectedLatest commit: bcca595 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
types/stylelint/index.d.ts
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[note] I recommend reviewing this file ignoring whitespaces.
"module": "commonjs", | ||
"lib": ["ES2021", "DOM"], | ||
"module": "Node16", | ||
"moduleResolution": "Node16", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
info
node16 and nodenext are currently identical, with the exception that they imply different target option values. If Node.js makes significant changes to its module system in the future, node16 will be frozen while nodenext will be updated to reflect the new behavior.
and since
--module nodenext implies --target esnext
--module node16 implies --target es2022
node16 is the right choice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thank you!
This change broke type definitions for CJS. It also didn’t add type definitions for ESM, meaning ESM types now fallback to the broken CJS types. |
}; | ||
}; | ||
|
||
declare const stylelint: PublicApi; | ||
|
||
export = stylelint; | ||
export default stylelint; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but the removal of the stylelint
namespace is related.
If you publish both CJS and ESM JavaScript code, you also need to publish both CJS and ESM type definitions. I have a hunch this is as simple as:
// index.d.mts
export * from './index.js'
export { default } from './index.js'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@remcohaszing Thank you. Is there a way to test both types on CI or localhost?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I’ll send a PR.
@remcohaszing @Mouvedia Thanks for the reminder! I'll open a patch PR after the ongoing 16.0.0 release. Or I'd appreciate it if you could open a PR instead of me. |
Follow-up to #5291
Wait for #7307Block #7160
This Pull Request mainly updates the TypeScript definitions for ESM.
Summary:
namespace
.tsconfig.json
for ESM and Node.js 18.test.d.ts
.is-plain-object
package to avoid type-check errors.See also: