egoist / egoist/parse-package-name

TypeScript type import error with module: Node16 or NodeNext

Open
#30 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
21
Forks
3
PR merge metrics
No merged PRs in 30d

Description

Right now, `parse-package-name` has two problems with its types:

* It uses the root-level `"types"` package.json key, rather than individual entries for CJS and ESM
* It uses the same `dist/index.d.ts` file for both CJS and ESM exports.

As a result, running type checking with TypeScript's [`module`](https://aka.ms/types#module) set to `"Node16"` or `"NodeNext"` gives:

```plaintext
index.ts:1:23 - error TS7016: Could not find a declaration file for module 'parse-package-name'. '/Users/josh/repos/repros/node_modules/.pnpm/parse-package-name@1.0.0/node_modules/parse-package-name/dist/index.mjs' implicitly has an 'any' type.
There are types at '/Users/josh/repos/repros/node_modules/parse-package-name/dist/index.d.ts', but this result could not be resolved when respecting package.json "exports". The 'parse-package-name' library may need to update its package.json or typings.

1 import { parse } from "parse-package-name";
~~~~~~~~~~~~~~~~~~~~
```

Full repro here: https://github.com/JoshuaKGoldberg/repros/tree/parse-package-name-node-module-export-types

Running `npx @arethetypeswrong/cli --pack .` after `pnpm build` in this repro shows:

```plaintext
❌ Import resolved to JavaScript files, but no type declarations were found. https://github.com/arethetypeswrong/arethetypeswrong.github.io/blob/main/docs/problems/UntypedResolution.md

┌───────────────────┬──────────────────────┐
│ │ "parse-package-name" │
├───────────────────┼──────────────────────┤
│ node10 │ 🟢 │
├───────────────────┼──────────────────────┤
│ node16 (from CJS) │ 🟢 (CJS) │
├───────────────────┼──────────────────────┤
│ node16 (from ESM) │ ❌ No types │
├───────────────────┼──────────────────────┤
│ bundler │ ❌ No types │
└───────────────────┴──────────────────────┘
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.