Can't access default export properties when `moduleResolution: 'NodeNext'`
ifiokjr opened this issue · comments
✨ Description
typescript@4.7.2
added ECMAScript support.
With the new setting activated, importing from this module doesn't recognize any of the properties available on the default export is
.
Currently, is
exports itself as a merged namespace and function.
declare function is(value: unknown): TypeName;
declare namespace is {
export var undefined: (value: unknown) => value is undefined;
}
export default is;
This doesn't seem to recognize properties with the new setting active.
I think that changing to use an interface as the main export should maintain the current behaviour and fix backward compatibility issues.
declare interface Is {
(value: unknown): TypeName;
undefined: (value: unknown) => value is undefined;
}
declare const is: Is;
export default is;
I've also opened an issue in the TypeScript repo.
💻 Code
tsconfig.json
{
"compilerOptions": {
"module": "ESNext",
"target": "ESNext",
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"moduleResolution": "NodeNext", // This is the added option
}
}
Example
import is from '@sindresorhus/is';
is.nullOrUndefined('something');
// => Property 'nullOrUndefined' does not exist on type 'typeof import("file:///node_modules/@sindresorhus/is/dist/index")
is.emptyObject({});
// => Property 'emptyObject' does not exist on type 'typeof import("file:///node_modules/@sindresorhus/is/dist/index")'.
📦 Versions
typescript
- 4.7.2@sindresorhus/is
- 4.6.0
It seems like this is a TypeScript issue, and the only way to currently fix it is to upgrade this package to support esm (type: module
).
I'll keep it open since it might be useful for those who run into the same issue.
Thanks @sindresorhus
The types are working in the playground now when the module is set to NodeNext
.