The current type definition won't work with CommonJS(cjs) import style, require('...') because we're lying to Typescript that we're exporting it as default. So typescript would expect that require('open-color') should look like {default: {white: ..., black: ....}}, not {white: ..., black: ....}. Yeah but it still working in some conditions like using esm with esModuleInterop prop. If esModuleInterop is true, typescript compiler mitigates the difference between esm and cjs styles. Otherwise, adopters will confront the below errors.
// cjs style importing
import oc = require('open-color') // Equivalent to `const oc = require('open-color')`
// `error TS2339: Property 'white' does not exist on type 'typeof 'open-color'` will be thrown while compiling.
oc.white
// `TypeError: Cannot read property 'default' of undefined` will be thrown on runtime while passing compiling
oc.default.white
The current type definition won't work with CommonJS(cjs) import style,
require('...')
because we're lying to Typescript that we're exporting it asdefault
. So typescript would expect thatrequire('open-color')
should look like{default: {white: ..., black: ....}}
, not{white: ..., black: ....}
. Yeah but it still working in some conditions like using esm withesModuleInterop
prop. IfesModuleInterop
is true, typescript compiler mitigates the difference between esm and cjs styles. Otherwise, adopters will confront the below errors.FYI, I submit a similar problem. https://github.com/unifiedjs/unified/issues/56