{"data":{"slug":"discovered-6d4545d5baceb5e40012e2d7fa1ded8145f7ac947a1f8f48","title":"Rjv Ts Code Style","summary":"Write and wire strict TypeScript and TSX in a pnpm monorepo with specific import rules, kebab-case file naming, shared tsconfig package, and no enums or any. Use when writing, moving, converting, or reviewing .ts\/.tsx files, package.json, or tsconfig.json.","url":"https:\/\/skillshunter.net\/skills\/discovered-6d4545d5baceb5e40012e2d7fa1ded8145f7ac947a1f8f48","json_url":"https:\/\/skillshunter.net\/api\/public\/v1\/skills\/discovered-6d4545d5baceb5e40012e2d7fa1ded8145f7ac947a1f8f48","markdown_url":"https:\/\/skillshunter.net\/skills\/discovered-6d4545d5baceb5e40012e2d7fa1ded8145f7ac947a1f8f48.md","download_url":"https:\/\/skillshunter.net\/skills\/discovered-6d4545d5baceb5e40012e2d7fa1ded8145f7ac947a1f8f48\/download","category":{"slug":"software-development","name":"Software & Development"},"editor_note":"Ensure the package.json includes the Node alias declaration: \"imports\": { \"#src\/*\": \".\/src\/*\" }, and that all relative and aliased imports include the real extension (e.g., .ts, .tsx).","instructions":"---\nname: rjv-ts-code-style\ndescription: \"How-to: write and wire strict TypeScript and TSX in a pnpm monorepo\u2014imports (package names, .\/, @\/ for bundled code, #src\/ for Node-run code, never ..\/), kebab-case files, shared tsconfig package, no enums or any. Use when writing, moving, converting or reviewing .ts\/.tsx files, package.json or tsconfig.json.\"\n---\n\n# TypeScript code style\n\nStrict TypeScript and TSX, written so a file can move without breaking and the same code runs in Node, a bundler and a Worker. Apply when you write or move a file; review checks it.\n\n## 1. Imports\n\nPick by where the target lives:\n\n| Target | Write | Example |\n|---|---|---|\n| a file in the same folder | `.\/` | `import { esc } from '.\/svg.ts'` |\n| another package | its package name | `import { bind } from '@acme\/engine'` |\n| elsewhere in a package a bundler builds (browser code, apps) | `@\/` (tsconfig `paths`) | `import { layoutOf } from '@\/grid\/input.ts'` |\n| elsewhere in a package Node runs (CLI, servers, libraries Node imports) | `#src\/` (package.json `imports`) | `import { StaleBase } from '#src\/store.ts'` |\n\n- **Never `..\/`.** One `..\/` today becomes `..\/..\/..\/` after the next move, and it hides where the file is.\n- Node runs `.ts` by stripping types and never reads tsconfig `paths`. So `@\/` in a Node-run package passes the type-check and fails at run time with \"module not found\"; Node-run packages use `#src\/`.\n- Declare the Node alias once per package: `\"imports\": { \"#src\/*\": \".\/src\/*\" }`. Node (14.6+), TypeScript, Vitest and esbuild all read it. It must start with `#`: an `@` name means an npm scope.\n- Write the real extension (`.ts`, `.tsx`) on every relative and aliased import. Node needs it; `allowImportingTsExtensions` allows it.\n- Never reach into another package's files (`@acme\/engine\/src\/...`): import what its `exports` offers, and add to that `exports` when something is missing.\n\nDone when `rg \"(from|import\\()\\s*['\\\"]\\.\\.\/\" --glob '*.{ts,tsx}'` finds nothing and every import is a package name, `.\/`, `@\/` or `#src\/`.\n\n## 2. Packages and files\n\n- Private internal packages share one scope (`@<repo>\/<name>`); only what is published carries the publishing scope.\n- Files are kebab-case: `grid-canvas.tsx`, `folder-store.ts`. Exported symbols keep their case (`GridCanvas`, `folderStore`).\n- A package's `exports` field names its entries; no barrel `index.ts` that re-exports half the package.\n- No Node built-in import (`node:fs`, or bare `fs`) outside a package's `src\/node\/` entry (`<pkg>\/node`), so the rest runs in a browser or a Worker.\n\n## 3. tsconfig\n\n- Shared config is a package (the turborepo pattern), e.g. `packages\/tsconfig` with `base.json`, `node.json` (`module`\/`moduleResolution` `nodenext`), `react.json` (`bundler`, `jsx: react-jsx`, DOM libs).\n- Each app and package has a short `tsconfig.json` extending one of them, adding only its own options:\n\n  ```json\n  { \"extends\": \"@acme\/tsconfig\/node.json\", \"include\": [\"src\", \"test\"] }\n  ```\n- The config package is a `workspace:*` devDependency of each package that extends it. No relative `extends` (`..\/..\/tsconfig.base.json`).\n- Each package has `\"type-check\": \"tsc --noEmit -p .\"`. Project references (`tsc -b`) refuse `noEmit`, so they are not used.\n\n## 4. TypeScript itself\n\n- `strict`, `noUncheckedIndexedAccess`, `erasableSyntaxOnly` (what Node's type stripping can run): no `enum`, no `namespace`, no constructor parameter properties. Use a union of string literals or an `as const` object.\n- No `any`. Parsed JSON or YAML is `unknown`, narrowed before use.\n- Exported functions declare parameter and return types.\n- Comments say why, or what a reader cannot see in the code; one line where one line does.\n\n## Related\n\n- React component conventions: the repo's components skill (components.build: parts, controlled and uncontrolled state, `data-slot`).\n","use_cases":["Writing new TypeScript or TSX files in a pnpm monorepo","Moving or converting existing .ts\/.tsx files to adhere to strict code style","Reviewing .ts\/.tsx files, package.json, or tsconfig.json for compliance with strict TypeScript conventions"],"limitations":[],"compatibility":[],"setup_tip":null,"sample_input":null,"sample_output":null,"source_url":"https:\/\/github.com\/rjvim\/ai-skills\/blob\/9a942086adef21dbd0c061d9d9e8fd5f43328bf6\/skills\/rjv-ts-code-style\/SKILL.md","source_commit":"9a942086adef21dbd0c061d9d9e8fd5f43328bf6","license":null,"version":null,"listing_approved_at":"2026-12-03","created_at":"2026-12-02T09:10:08.000000Z","updated_at":"2026-12-03T16:19:55.000000Z","seo_title":"Strict TypeScript and TSX Code Style for pnpm Monorepos","seo_description":"Learn how to write and wire strict TypeScript and TSX in a pnpm monorepo with specific import rules, kebab-case file naming, shared tsconfig package, and no enums or any.","seo_keywords":["TypeScript code style","pnpm monorepo","strict TypeScript","TSX conventions","import rules","kebab-case files","shared tsconfig package"]}}