Repository navigation
fix(#542): resolve tsc --noEmit errors in core-data-shim - #545
Conversation
- 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
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThis PR resolves six TypeScript strict mode errors in the core-data shim. The implementation now explicitly handles null from ChangesStrict Type Checking Alignment
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
Description
Strict TypeScript checking (
npx tsc --noEmit) surfaced 3 errors inresources/js/visual-editor/vendor/core-data-shim.tsand a related cluster in its test file. Vitest passed because esbuild skips strict type checks, but taggingv1.0.0requires a clean tsc pass. This PR fixes them.Closes: #542
Type of Change
Related Issue
Issue: #542
Motivation and Context
Per the v1.0.0 audit,
tsc --noEmitmust be green before tagging. The shim file had three real type holes that strict checking caught (one nullable-return, one misuseduseSelectgeneric, one cascading implicit-any), plus mirrored holes in its test file.Changes Made
saveEditedEntityRecordwhengetEditedEntityRecordreturnsnullso the payload spread no longer trips strictEntityRecordtyping.useSelect<ReturnShape>generic inuseEntityProp—useSelect's type parameter is theMapSelectcallback, not the return shape — and type theselectcallback so it no longer falls back toany.vi.fnfetcher mocks in the test file to matchtypeof fetch((input: RequestInfo | URL, init?: RequestInit)).useEntityBlockEditorrenderHookcalls. The previousas readonly Array<...>applied to the returned tuple (not the blocks array) and used the invalidreadonly Array<>modifier syntax.How Has This Been Tested?
Testing Environment:
release/1.0Tests Performed:
npx tsc --noEmit— no errors incore-data-shim.tsor its test filenpx vitest run resources/js/visual-editor/vendor/__tests__/core-data-shim.test.tsx— 72/72 passingAccessibility Tests Run
Tests Added
Test details: Existing 72 tests in
core-data-shim.test.tsxcontinue to pass; the file's own type holes are now also caught by tsc.Documentation
Pre-Submission Checklist
Follow-ups (pre-existing, surfaced during manual verification)
Two pre-existing issues were observed on
release/1.0during manual verification of this fix; separate follow-up issues will be filed:small,large) emitted byFontSizePickerSelectinside@wordpress/componentswhen a block is selected.Both reproduce without this branch's changes and are out of scope here.
Summary by CodeRabbit
Bug Fixes
Tests