Skip to content

chore(ts): finish the TypeScript migration#54

Merged
oxyc merged 5 commits into
mainfrom
chore/ts-finish
Jun 1, 2026
Merged

chore(ts): finish the TypeScript migration#54
oxyc merged 5 commits into
mainfrom
chore/ts-finish

Conversation

@oxyc

@oxyc oxyc commented May 31, 2026

Copy link
Copy Markdown
Member

Final pass on the TS migration (#41 epilogue). After this, every .js / .jsx under resources/scripts/ is TypeScript.

Files

File Notes
admin-chat.tsx (from .jsx) Entry — DOM-mount the App. Pure rename.
admin-settings.tsx (from .jsx) Entry — mounts 4 dataview roots. Pure rename.
app.tsx (from .jsx) Typed CustomEvent<{ uuid?: string }> for the cross-page resume handler.
skill-editor.tsx (from .jsx) SkillMeta + SkillModelProvider shapes; casts at the SelectControl options boundary (the TranslatableText branding rejects bare strings) and at registerPlugin (icon is typed required since 6.7 but the runtime still accepts plugins without one).
editor/block-toolbar-actions.tsx (from .jsx) Typed BlockEditProps shape passed through the HOC; VoiceLang for the translate-target enumeration.
editor/write-at-cursor.ts (from .jsx) No JSX — .ts. Typed Event-target narrowing in isInsideEditorCanvas; one-off iframe brand for the attach-once flag.
editor/diff.ts (from .js) Exports DiffSegmentType, DiffSegment, ModifiedLine, DiffRow. ToolCallFallback.tsx can drop its inline shape interface in a follow-up.
editor/__tests__/diff.test.ts (from .js) Same tests; @types/jest added so describe / test / expect resolve. Inline segment literals use DiffSegment[] so the discriminated union is satisfied.

Sundry

  • types/css.d.ts — new ambient declaration so import "./foo.css" side-effect imports in entry files resolve. Lives in its own file (not the existing globals.d.ts) so it's loaded as a global script.
  • @types/wordpress__editor + @types/wordpress__plugins added — used by skill-editor.tsx's PluginDocumentSettingPanel + registerPlugin.
  • @types/jest added — used by the migrated test file. Listed in tsconfig.json compilerOptions.types.
  • webpack.config.js entry paths updated from .jsx to .tsx.

Real bug surfaced by the migration

UndoContext.UndoableAction.auditId was typed string but the audit-log row id is always number (matches Storage\AuditLog.id). Production code already passed a number from use-runtime-adapter.ts; the modal's onUndo prop and UndoContext type signatures now agree end-to-end. pending and error also widened to optional / nullable to match the runtime adapter's writes.

Verification

  • npm run typecheck — clean
  • npm run lint:js0 warnings, 0 errors
  • npm run build — succeeds
  • npm run test:unit — 17/17 pass

🤖 Generated with Claude Code

oxyc and others added 5 commits May 31, 2026 19:22
Final pass: every `.js` / `.jsx` under `resources/scripts/` is now
TypeScript (except none — they're all migrated).

## Files

| File | Notes |
|---|---|
| `admin-chat.tsx` (from `.jsx`) | Entry point — DOM-mount the App. No type changes needed beyond the rename. |
| `admin-settings.tsx` (from `.jsx`) | Entry point — mounts 4 dataview roots. |
| `skill-editor.tsx` (from `.jsx`) | Adds `SkillMeta` + `SkillModelProvider` shapes; casts at the `SelectControl` `options` boundary (`TranslatableText` branding) and at `registerPlugin` (`icon` is typed required since 6.7 but runtime accepts plugins without one). |
| `app.tsx` (from `.jsx`) | Typed CustomEvent dispatch handler. |
| `editor/block-toolbar-actions.tsx` (from `.jsx`) | Typed `BlockEditProps` shape passed through the HOC; `VoiceLang` for the translate-target enumeration. |
| `editor/write-at-cursor.ts` (from `.jsx`) | No JSX in the file — `.ts` works. Typed Event-target narrowing in `isInsideEditorCanvas`; uses a one-off iframe brand for the attach-once flag. |
| `editor/diff.ts` (from `.js`) | Exports `DiffSegmentType`, `DiffSegment`, `ModifiedLine`, `DiffRow`. `ToolCallFallback.tsx` can drop its inline shape interface in a follow-up. |
| `editor/__tests__/diff.test.ts` (from `.js`) | Same tests; `@types/jest` added so `describe` / `test` / `expect` resolve. Inline segment literals use the `DiffSegment` array type so the discriminated union is satisfied. |

## Sundry

- **`types/css.d.ts`** — new ambient declaration so `import "./foo.css"`
  side-effect imports in the entry files resolve. Lives in its own file
  (not the existing `globals.d.ts`) so it's loaded as a global script.
- **`@types/wordpress__editor` + `@types/wordpress__plugins`** added — used
  by `skill-editor.tsx`'s `PluginDocumentSettingPanel` + `registerPlugin`.
- **`@types/jest`** added — used by the migrated test file. Listed in
  `tsconfig.json` `compilerOptions.types`.
- **`webpack.config.js`** entry paths updated from `.jsx` to `.tsx`.
- **Real bug surfaced in the migration**: `UndoContext.UndoableAction.auditId`
  was typed `string` but the audit-log row id is always `number` (matches
  `Storage\AuditLog` `id` column). Production code passes a number from
  `use-runtime-adapter.ts`; `app.tsx` -> `assistant-modal` -> `UndoContext`
  pipe types now agree. `pending` and `error` also widened to optional /
  nullable to match the runtime adapter's writes.

## Verification

- `npm run typecheck` — clean
- `npm run lint:js` — 0 warnings, 0 errors
- `npm run build` — succeeds
- `npm run test:unit` — 17/17 pass

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…tor install

CI's npm ci was failing with 'Missing: date-fns@4.4.0 from lock file' —
the lock that landed with the .ts migration commit had a transitive
inconsistency where the new @types/wordpress__editor pulled in
@wordpress/media-utils which had been resolved against a different
date-fns minor version than what was pinned. A clean regen settled
everything to consistent versions; `npm ci` now passes locally.

No code change, just the lock file.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…rations instead

The @types/wordpress__editor + @types/wordpress__plugins packages I
added in the previous commit pull in @wordpress/media-utils and
@wordpress/components@33 as peer trees that resolve transitive deps
(date-fns specifically) to different versions on CI's npm vs local —
which breaks 'npm ci' with 'Missing: date-fns@4.4.0 from lock file'
even after lock regen.

Webpack externalises @wordpress/editor + @wordpress/plugins +
@wordpress/block-editor from window.wp.* at runtime anyway, so we only
need just-enough types to compile. Added resources/scripts/types/
wp-editor.d.ts with narrow ambient declarations for the three symbols
skill-editor / block-toolbar-actions actually use:

- PluginDocumentSettingPanel (children + name + title)
- registerPlugin (icon optional, runtime-truth)
- BlockControls (group + children)

skill-editor.tsx is back to plain imports; the SelectControl 'as never'
options cast still handles the TranslatableText branding without the
@types peer trees being involved.

Verified: typecheck clean, lint clean, build succeeds, tests pass,
'npm ci' succeeds locally.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Mirrors the root generogrowth repo's existing supply-chain setting:
'npm install' (and on CI 'npm ci') will refuse package versions
published in the last 7 days. Both:

- Defends against rapid-publish supply-chain attacks (typosquats,
  compromised credentials, malicious post-install scripts).
- Keeps lock-file resolutions stable between this dev machine
  (where ~/.npmrc already sets a min-release-age) and CI runners
  (which were previously resolving '^4.x' on @wordpress/components'
  date-fns peer to whatever shipped yesterday, then complaining
  'Missing: date-fns@4.4.0 from lock file' against a lock that pinned
  the older release).

Requires npm >=11.10; silently ignored by older npm so safe to commit.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Previous .npmrc / workflow-bump attempts didn't resolve the CI vs local
resolution mismatch. `@wordpress/components` declares `date-fns: ^4.x`
which local npm 11.14 (with min-release-age) resolves to 4.3.0 while CI
npm 10.x resolves to whatever shipped last (4.4.0 currently). The lock
mismatch trips 'npm ci'.

Adding 'date-fns: 4.3.0' to package.json's 'overrides' forces every
transitive consumer to the same version regardless of how the host npm
resolves `^4.x`, so the committed lock is portable. Reverts the
.npmrc + workflow npm-bump from the prior commits — no longer needed.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@oxyc oxyc merged commit 62cc3f0 into main Jun 1, 2026
3 checks passed
@oxyc oxyc deleted the chore/ts-finish branch June 1, 2026 15:09
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