Skip to content

Point the npm package's types at the declarations Kotlin/JS emits - #431

Open
holodorum wants to merge 1 commit into
kson-org:mainfrom
holodorum:fix/npm-package-types
Open

Point the npm package's types at the declarations Kotlin/JS emits#431
holodorum wants to merge 1 commit into
kson-org:mainfrom
holodorum:fix/npm-package-types

Conversation

@holodorum

Copy link
Copy Markdown
Collaborator

The generated package.json advertised ./kson-kson-lib.d.ts at the package root. That file was never in the tarball: Kotlin/JS emits .d.mts beside each module, and the copy step meant to hoist declarations to the root matched *.d.ts, so it silently copied nothing.

Under moduleResolution: nodenext this went unnoticed — the node condition matches first and TypeScript falls back to the sibling .d.mts. Under bundler resolution, the Vite and Next.js default, it failed outright:

error TS2307: Cannot find module '@kson_org/kson' or its corresponding type declarations.

So the published package had no usable types for anyone resolving that way.

The fix

Each export condition now names the declarations sitting beside the module it resolves to, with types listed first so it is reachable — Node and TypeScript take the first matching key within a condition, and a types entry after default is never read.

The default condition is load-bearing rather than boilerplate: bundler resolution uses the conditions ["types", "import"], which match neither browser nor node, so without it those projects still fail to resolve.

Also corrects the README's TypeScript example, which imported from kson rather than @kson_org/kson and so could not resolve, and the -Prelease=true missing from the documented build step.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant