Skip to content

fix(#542): resolve tsc --noEmit errors in core-data-shim - #545

Merged
ViewFromTheBox merged 1 commit into
release/1.0from
bugfix/542-tsc-noemit-core-data-shim-errors
Jun 8, 2026
Merged

ViewFromTheBox merged 1 commit into
release/1.0from
bugfix/542-tsc-noemit-core-data-shim-errors

Conversation

@ViewFromTheBox

@ViewFromTheBox ViewFromTheBox commented Jun 8, 2026 •

Copy link
Copy Markdown
Member

Description

Strict TypeScript checking (npx tsc --noEmit) surfaced 3 errors in resources/js/visual-editor/vendor/core-data-shim.ts and a related cluster in its test file. Vitest passed because esbuild skips strict type checks, but tagging v1.0.0 requires a clean tsc pass. This PR fixes them.

Closes: #542

Type of Change

  • Bug fix (fixes an issue)

Related Issue

Issue: #542

Motivation and Context

Per the v1.0.0 audit, tsc --noEmit must be green before tagging. The shim file had three real type holes that strict checking caught (one nullable-return, one misused useSelect generic, one cascading implicit-any), plus mirrored holes in its test file.

Changes Made

  • Guard saveEditedEntityRecord when getEditedEntityRecord returns null so the payload spread no longer trips strict EntityRecord typing.
  • Drop the misused useSelect<ReturnShape> generic in useEntityProp — useSelect's type parameter is the MapSelect callback, not the return shape — and type the select callback so it no longer falls back to any.
  • Widen two vi.fn fetcher mocks in the test file to match typeof fetch ((input: RequestInfo | URL, init?: RequestInit)).
  • Split the tuple destructure from the type cast on two useEntityBlockEditor renderHook calls. The previous as readonly Array<...> applied to the returned tuple (not the blocks array) and used the invalid readonly Array<> modifier syntax.

How Has This Been Tested?

Testing Environment:

  • Operating System: macOS (Darwin 25.5.0)
  • Browser: Safari (dev app)
  • PHP Version: N/A
  • Project Version: release/1.0

Tests Performed:

  1. npx tsc --noEmit — no errors in core-data-shim.ts or its test file
  2. npx vitest run resources/js/visual-editor/vendor/__tests__/core-data-shim.test.tsx — 72/72 passing
  3. Manual smoke test of the save-edited-entity flow in the dev app — no regression

Accessibility Tests Run

  • N/A — type-only and defensive null-guard changes; no UI surface affected

Tests Added

  • All tests passing

Test details: Existing 72 tests in core-data-shim.test.tsx continue to pass; the file's own type holes are now also caught by tsc.

Documentation

  • N/A

Pre-Submission Checklist

  • Code passes all tests
  • Code has been linted
  • Self-review completed
  • No new warnings generated

Follow-ups (pre-existing, surfaced during manual verification)

Two pre-existing issues were observed on release/1.0 during manual verification of this fix; separate follow-up issues will be filed:

  • Post editor title block reads correctly but does not update as the user types.
  • Duplicate React keys (small, large) emitted by FontSizePickerSelect inside @wordpress/components when a block is selected.

Both reproduce without this branch's changes and are out of scope here.

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling when saving records with no changes
  • Tests

    • Updated test infrastructure for entity record operations and hook behavior

- Guard `saveEditedEntityRecord` when `getEditedEntityRecord` returns null
  so the payload spread no longer trips strict `EntityRecord` typing.
- Drop the misused `useSelect<ReturnShape>` generic in `useEntityProp` —
  `useSelect`'s type parameter is the MapSelect callback, not the return
  shape — and type the `select` callback so it no longer falls back to
  `any`.
- In the companion test file, widen two `vi.fn` fetcher mocks to match
  `typeof fetch`, and split the tuple destructure from the type cast on
  two `useEntityBlockEditor` renderHook calls (the previous
  `as readonly Array<...>` applied to the tuple, not the blocks array,
  and used an invalid `readonly Array<>` modifier).

Closes #542
@coderabbitai

coderabbitai Bot commented Jun 8, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 19f6717b-59a2-4bdf-af65-930fb2224c8a

📥 Commits

Reviewing files that changed from the base of the PR and between f6eecb8 and 98fafbf.

📒 Files selected for processing (2)
  • resources/js/visual-editor/vendor/__tests__/core-data-shim.test.tsx
  • resources/js/visual-editor/vendor/core-data-shim.ts

📝 Walkthrough

Walkthrough

This PR resolves six TypeScript strict mode errors in the core-data shim. The implementation now explicitly handles null from getEditedEntityRecord and simplifies type annotations in useEntityProp. Tests are updated to match the corrected fetcher signature and adjust hook result destructuring patterns.

Changes

Strict Type Checking Alignment

Layer / File(s) Summary
saveEditedEntityRecord null guard and useEntityProp typing
resources/js/visual-editor/vendor/core-data-shim.ts
saveEditedEntityRecord now explicitly returns null when getEditedEntityRecord returns null instead of attempting to process a null value. useEntityProp removes an overly specific generic type annotation from its useSelect call, keeping the selector logic and return structure intact.
Test mock and destructuring updates for implementation compatibility
resources/js/visual-editor/vendor/__tests__/core-data-shim.test.tsx
The "saveEntityRecord re-triggers the list resolver" test updates the fetcher mock signature to (input: RequestInfo | URL, init?: RequestInit) with URL normalization via String(input), matching the shim's calling convention. useEntityBlockEditor tests capture hook output as rawBlocks and apply explicit type casting, aligning with the refined type shape.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • ArtisanPack-UI/visual-editor#328: The main PR's changes directly modify the existing resources/js/visual-editor/vendor/core-data-shim.ts implementation—specifically saveEditedEntityRecord and useEntityProp—which are part of the same @wordpress/core-data shim introduced by PR #328.
  • ArtisanPack-UI/visual-editor#355: The main PR's targeted fixes in saveEditedEntityRecord (returning null when there's no edited record) and test adjustments are directly aligned with the shim/test expansion introduced in PR #355's core-data shim work.
  • ArtisanPack-UI/visual-editor#417: The main PR's updates to fetcher mock signature and null/edited handling in saveEditedEntityRecord directly align with the resolver-driven shim refactor in #417 that changed resolver/fetcher and edited-record flow.

Poem

🐰 A rabbit hops through types so strict,
Each null now guarded, logic picked,
Fetcher calls wear formal dress,
Tests aligned—we pass the test! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly references the linked issue (#542) and accurately summarizes the main change: resolving TypeScript compilation errors in the core-data-shim file.
Linked Issues check ✅ Passed The PR successfully addresses all coding requirements from issue #542: handling nullable EntityRecord returns, adding explicit type for select callback, correcting test typings, and ensuring tsc --noEmit passes without errors.
Out of Scope Changes check ✅ Passed All changes are directly scoped to resolving the six tsc --noEmit errors in core-data-shim.ts and its test file; no unrelated modifications are present.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bugfix/542-tsc-noemit-core-data-shim-errors

Comment @coderabbitai help to get the list of available commands and usage tips.

@ViewFromTheBox
ViewFromTheBox merged commit 62b152b into release/1.0 Jun 8, 2026
6 checks passed
@github-project-automation github-project-automation Bot moved this from In Review to Done in ArtisanPack UI Overview Jun 8, 2026
@ViewFromTheBox
ViewFromTheBox deleted the bugfix/542-tsc-noemit-core-data-shim-errors branch June 8, 2026 20:22
@coderabbitai coderabbitai Bot mentioned this pull request Jun 8, 2026
11 of 29 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

TypeScript build failing: 6 tsc --noEmit errors in core-data-shim.ts

1 participant