Skip to content

Migrate source to TypeScript (/typescript eslint config) - #71

Merged
kpal81xd merged 2 commits into
mainfrom
migrate-to-typescript
Jul 6, 2026
Merged

kpal81xd merged 2 commits into
mainfrom
migrate-to-typescript

Conversation

@kpal81xd

@kpal81xd kpal81xd commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

What

Migrates the codebase from JSDoc-typed JavaScript to TypeScript and switches ESLint to the @playcanvas/eslint-config/typescript export.

  • All 8 src/ files renamed .js → .ts (via git mv, history preserved) with JSDoc types converted to explicit TS annotations and TSDoc comments (no type braces, no typedefs)
  • test/utils.js → test/utils.ts; the 27 mocha spec files stay JS and run the TS source directly via native node type stripping — zero new runtime/loader dependencies (guarded by erasableSyntaxOnly)
  • eslint.config.mjs swapped to the /typescript export, which bundles prettier and the import resolver — config shrank to ignores + globals + one chai override
  • No any anywhere: internal TS compiler APIs (jsDoc, getElementTypeOfArrayType, …) are typed via an InternalNode shape; the literal-extraction path uses a recursive LiteralValue union; parsed attributes use a typed AttributeData; two internal APIs replaced with public equivalents (isPrefixUnaryExpression, boolean-literal kind checks)
  • Rollup builds src/index.ts through the existing swc plugin; tsc -p tsconfig.build.json emits declarations as before (now with more accurate signatures, e.g. updateProgram(): ValidationError[])

Notable side changes

  • typescript lockfile bumped 5.5.4 → 5.9.3 (package.json range ^5.5.3 unchanged — fresh installs already resolve 5.9). Needed for erasableSyntaxOnly; also surfaced a latent bug where rollup.config.mjs read lib.es2022.sharedmemory.d.ts, removed in TS 5.9 — libs.d.ts generation now skips missing lib files
  • package.json files trimmed per the new package-json lint rules (dist/index.js ships via main; README/LICENSE auto-included) — verified with npm pack --dry-run + publint
  • engines.node raised to >=22.0.0; CI already runs node 24
  • eslint-config-prettier devDep removed (ships inside the eslint config); @types/node added

Verification

  • lint, prettier, tsc --noEmit, build, publint all green; 184 mocha tests pass
  • Emitted types/ keep .ts specifiers; verified resolvable by a consumer project under both bundler and nodenext resolution, with and without skipLibCheck
  • Behavioral equivalence proven against main: built both branches and ran parseAttributes + getAttributes over all 32 test fixtures through each dist/index.node.mjs — JSON outputs are byte-identical (even across the TS 5.5.4/5.9.3 runtime difference). A line-level diff of the compiled node bundles was audited; every hunk is a rename, hoisted local, or a proven-equivalent API swap

Not included: strict: true — deferred to a follow-up so type-tightening can't hide migration regressions.

…escript

- Rename all src files .js -> .ts, convert JSDoc types to explicit TS annotations
- Convert test/utils.js -> utils.ts; tests run on native node type stripping (no new loaders)
- Swap eslint config to the /typescript export; drop redundant prettier/jsdoc overrides
- Add InternalNode/LiteralValue/AttributeData types; no explicit any anywhere
- Bump typescript lockfile to 5.9.3 (matches what ^5.5.3 resolves for consumers)
- Guard rollup libs.d.ts generation against lib files removed in newer TS
- Raise engines to node >=22
@kpal81xd kpal81xd self-assigned this Jul 6, 2026
- dist/** ignore ships in the config's default ignores
- globals block was dead weight: node globals come from the config, and
  test files import describe/it from mocha explicitly (no-undef verified active)
- drop the now-unused globals devDependency
@kpal81xd
kpal81xd merged commit a663cc9 into main Jul 6, 2026
3 checks passed
@kpal81xd
kpal81xd deleted the migrate-to-typescript branch July 6, 2026 11:07
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