question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Not compatible with TypeScript

See original GitHub issue

Long story short - publishing d.ts should fix an issue, with a breaking change (probably it worth to complement the update with a codemod)

- import * as cx from 'classnames';
+ import cx from 'classnames';

The current version of classnames is not exposing default in a ESM format, as well as d.ts has no mention of it. As a result import * as cx from 'classnames', is a correct way to load this module from a TypeScript perspective. However, if the result code would be compiled down using Babel, and Babel can compile TypeScript this would lead to the runtime exception - cx is not an object

The reason is _interopRequireWildcard helper, which would convert classnames to the {default: classnames}, which is yet - not a function.

While webpack is managing “harmony imports” by it’s own, and managing in a correct (from TypeScript point of view) way - import * == module.exports, babel is more ESM modules compatible, and wildcard import is working differently in that case.

Proposal:

  • update classnames to contain _esModule property to make it ESM compatible.
  • ideally - expose ESM bundle
  • update d.ts to contain only default export (breaking change), to resolve this issue.

See https://github.com/babel/babel/pull/10574#issuecomment-544107112 for details.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
mitsuruogcommented, Nov 4, 2019

Seems index.d.ts is not published. please add the bellow section to your package.json

"files": [
  "index.d.ts"
]

or the workaround is just to use @types/classnames for a while.

2reactions
nicolo-ribaudocommented, Oct 19, 2019

The d.ts file already contains export default classNames: https://github.com/JedWatson/classnames/blob/5d971e41f3b9c8047b61503952a413f00122b52c/index.d.ts#L15

Which error does typescript report if you do import classnames from "classnames"?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Documentation - Type Compatibility - TypeScript
Type compatibility in TypeScript is based on structural subtyping. Structural typing is a ... Static members and constructors do not affect compatibility.
Read more >
TypeScript arguing that an interface is not compatible with ...
TypeScript arguing that an interface is not compatible with generic type T, although T extends that interface.
Read more >
Eslint Version is not compatible with Typescript version #291
WARNING: You are currently running a version of TypeScript which is not officially supported by typescript-estree.
Read more >
Understanding type compatibility | Learn TypeScript
i.e., how TypeScript decides whether types are compatible. Basic type compatibility. Let's explore type compatibility in an exercise. TypeScript Open exercise ...
Read more >
ts-node - npm
Older versions of typescript are incompatible with @tsconfig/node16 . In those cases we will use an older default configuration.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found