Skip to content

fix: install @types packages with the TS registry variants - #1113

Open
harshbhx wants to merge 1 commit into
DavidHDev:mainfrom
harshbhx:feat/fix-ts-types-dependencies
Open

harshbhx wants to merge 1 commit into
DavidHDev:mainfrom
harshbhx:feat/fix-ts-types-dependencies

Conversation

@harshbhx

Copy link
Copy Markdown

Summary

The TypeScript variants of components that import three or matter-js now also install the matching @types/* package, so a TS project compiles right after shadcn add without manual steps.

Closes #1112

Problem

three and matter-js don't ship their own type definitions, but the TS registry items only listed the runtime package under dependencies. For example Lanyard-TS-CSS.json had three@^0.180.0 and nothing else, so after installing the component tsc reports:

error TS7016: Could not find a declaration file for module 'three'.

It isn't specific to pnpm; the registry content is the same whichever package manager runs the install.

Solution

@jsrepo/shadcn only writes dependencies to the item JSON, so the types are added in jsrepo.config.ts, in the same place withLinkedDependencies already post-processes the generated files:

  • defineComponent scans the files of each TS variant for imports of three, @react-three/fiber, @react-three/drei and matter-js, and maps them to @types/three / @types/matter-js.
  • The build then writes those as devDependencies (the shadcn registry-item schema supports the field, and the CLI installs them with -D).
  • Versions are read from this repo's own devDependencies, so they stay in line with the runtime packages. Adding a package to TYPES_PACKAGES is all it takes to cover another one later.

JS variants are untouched, and no component code changed.

Changes

File Change
jsrepo.config.ts Detect which TS variants need @types, write them as devDependencies
public/r/*-TS-CSS.json, public/r/*-TS-TW.json Regenerated for the 8 affected components (16 files, +3 lines each)

Affected components: BlobCursor, ColorBends, Hyperspeed, Lanyard, ModelViewer, PaperCrumple (@types/three) and FallingText, FolderFloat (@types/matter-js).

Before / After

Lanyard-TS-CSS.json:

 	"dependencies": [
 		"three@^0.180.0"
+	],
+	"devDependencies": [
+		"@types/three@^0.180.0"
 	]

How to test

  1. npm run registry:build
  2. git status public/r should show only the 16 TS files above, and none of the *-JS-* files.
  3. In a TypeScript project, run npx shadcn@latest add <path or URL of Lanyard-TS-CSS.json>; @types/three is added to devDependencies next to three.

Testing done

Ran in GitHub Actions on my fork (run):

  • npm ci and npx jsrepo build pass; exactly the 16 expected files change, and none of the JS variants gained a devDependencies field.
  • A fresh project with three and strict TypeScript fails with TS7016 before adding @types/three and compiles cleanly after.
  • shadcn add against the rebuilt Lanyard-TS-CSS.json created Lanyard.css and Lanyard.tsx and put three in dependencies and @types/three in devDependencies.
  • prettier --check jsrepo.config.ts passes.

Not covered: I only tried the shadcn CLI. I haven't run jsrepo add against the new files, and I haven't checked every one of the 8 components in a real app. I also didn't add updates entries in Information.js, since no component code changed; happy to add them if you'd like them on the changelog.

Notes

  • The docs "Dependencies" panel (manual install) still lists only runtime packages. I kept this PR to the registry so it stays small; I can follow up with the types there if you want.
  • @types/matter-js comes from the repo's existing ^0.19.8 pin, while matter-js is ^0.20.0; bumping that is a separate decision.

The TS variants of components that import three or matter-js only listed the
runtime package, so the CLI never installed its type definitions and tsc failed
with TS7016. Add the matching @types package as a devDependency for those
variants, taking the version from package.json, and regenerate the 16 affected
registry files.

Closes DavidHDev#1112

This branch has not been deployed

No deployments
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.

[BUG]: TypeScript Type Definitions Missing When Installing Components with pnpm

1 participant