-
Notifications
You must be signed in to change notification settings - Fork 562
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 TypeScript types when using require #276
Conversation
The package uses commonjs, but it’s typed as if it contains faux ESM. This was problematic for people using `require` or the new `node16` module resolution.
Please @JedWatson could you help merge/publish this? This is blocking cases where TypeScript "nodenext" resolution is being used. See this issue for details: microsoft/TypeScript#49189 |
Hi, FYI this is a breaking change for TypeScript consumers which is unexpected in a patch version of the classnames package. Before, we could I understand that this change was made to support a newer TS resolution option, but changes to typings like this should be done carefully to avoid breaking existing consumers. May I ask why you are using |
I see how this affects you and why you consider this breaking. However, I believe this was a bug fix. Any change of behaviour can break code, including bug fixes. You were previously relying on this bug. According to the readme, correct usage of this package is: // CJS
const classNames = require('classnames') // ESM
import classNames from 'classnames' However, before this PR, according to the TypeScript type definitions, correct usage was: // CJS
const classNamesExports = require('classnames')
const classNames = classNamesModule.default // ESM
import classNamesExports from 'classnames'
const classNames = classNamesModule.default The latter technically works too, because The latter didn’t work because it was typed correctly. It worked by accident. The situation you are describing is usage of this package inside a module bundler that allows you to import
The JavaScript ecosystem is slowly moving towards ESM. In order to be able to use newer packages or updates, one has to keep up.
This isn’t a matter of opinion, but of statistics that aren’t presented. I’m inclined to believe this is correct though. What matters is correctness though, not usage statistics.
This didn’t break usage. It highlights a problem in those consumers’ configuration. You would’ve run into the same problem eventually if you added another properly typed dependency. For more information, see https://github.com/DefinitelyTyped/DefinitelyTyped#a-package-uses-export--but-i-prefer-to-use-default-imports-can-i-change-export--to-export-default |
I stand by my previous comment, but I learnt that it is possible to also support the |
This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [classnames](https://github.com/JedWatson/classnames) | dependencies | minor | [`2.3.1` -> `2.5.1`](https://renovatebot.com/diffs/npm/classnames/2.3.1/2.5.1) | --- ### Release Notes <details> <summary>JedWatson/classnames (classnames)</summary> ### [`v2.5.1`](https://github.com/JedWatson/classnames/blob/HEAD/HISTORY.md#v251--2023-12-29) [Compare Source](JedWatson/classnames@v2.5.0...v2.5.1) - Remove `workspaces` field from package ([#​350](JedWatson/classnames#350)) ### [`v2.5.0`](https://github.com/JedWatson/classnames/blob/HEAD/HISTORY.md#v250--2023-12-27) [Compare Source](JedWatson/classnames@v2.4.0...v2.5.0) - Restore ability to pass a TypeScript `interface` ([#​341](JedWatson/classnames#341)) - Add `exports` field to package ([#​342](JedWatson/classnames#342)) ### [`v2.4.0`](https://github.com/JedWatson/classnames/blob/HEAD/HISTORY.md#v240--2023-12-26) [Compare Source](JedWatson/classnames@v2.3.3...v2.4.0) - Use string concatenation to increase performance thanks [Jon Koops](https://github.com/jonkoops) ([#​336](JedWatson/classnames#336)) ### [`v2.3.3`](https://github.com/JedWatson/classnames/blob/HEAD/HISTORY.md#v233--2023-12-21) [Compare Source](JedWatson/classnames@v2.3.2...v2.3.3) - Fix default export, thanks [Remco Haszing](https://github.com/remcohaszing) ([#​301](JedWatson/classnames#301)) - Fix types for read-only arrays, thanks [Ben Thompson](https://github.com/BenGearset) ([#​307](JedWatson/classnames#307)) - Replace README examples with functional-style components, thanks [JoeDGit](https://github.com/JoeDGit) ([#​303](JedWatson/classnames#303)) ### [`v2.3.2`](https://github.com/JedWatson/classnames/blob/HEAD/HISTORY.md#v232--2022-09-13) [Compare Source](JedWatson/classnames@v2.3.1...v2.3.2) - Fix TypeScript types when using require, thanks [Mark Dalgleish](https://github.com/markdalgleish) ([#​276](JedWatson/classnames#276)) - Fix toString as `[Object object]` in a vm, thanks [Remco Haszing](https://github.com/remcohaszing) ([#​281](JedWatson/classnames#281)) </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOC4xNDIuNSIsInVwZGF0ZWRJblZlciI6IjM4LjE0Mi41IiwidGFyZ2V0QnJhbmNoIjoibWFzdGVyIiwibGFiZWxzIjpbXX0=--> Reviewed-on: https://gitea.bruyant.xyz/alexandre/PaletteSwitcher/pulls/48 Co-authored-by: Renovate <[email protected]> Co-committed-by: Renovate <[email protected]>
The package uses commonjs, but it’s typed as if it contains faux ESM. This was problematic for people using
require
or the newnode16
module resolution.