Declare @types/react and @types/lodash as optional peers of slate-react - #6110
Open
unrevised6419 wants to merge 1 commit into
Open
unrevised6419 wants to merge 1 commit into
unrevised6419 wants to merge 1 commit into
Conversation
🦋 Changeset detectedLatest commit: 9b1f0ae The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
unrevised6419
force-pushed
the
fix/slate-react-types-peer-deps
branch
from
September 20, 2026 00:29
487beab to
6a2fcf5
Compare
slate-react's shipped .d.ts files import React types (33 references plus nine `/// <reference types="react" />` directives) and, in hooks/android-input-manager, lodash's `DebouncedFunc`. Neither typings package was declared in package.json — both were only devDependencies. A hoisted node_modules layout resolves them by accident. pnpm's isolated linker with a global virtual store does not: the package is linked from a store path outside the consuming project, TypeScript resolves a package's imports from where that package physically lives, so `react` resolves to the untyped `react/index.js`. Consumers then get TS7016 implicit-any errors, or silently degraded `any` props, for the editor components. Both entries are optional peers so JavaScript-only consumers do not get unmet-peer warnings. The existing react, react-dom, slate and slate-dom peer ranges are unchanged. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
unrevised6419
force-pushed
the
fix/slate-react-types-peer-deps
branch
from
September 20, 2026 00:35
6a2fcf5 to
9b1f0ae
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
slate-react's shipped type declarations reference typings packages thatpackage.jsonnever declares:react— 33 references acrossdist/**/*.d.ts, plus nine/// <reference types="react" />directives (use-slate-static.d.ts,use-focused.d.ts,use-element.d.ts, …)lodash—dist/hooks/android-input-manager/android-input-manager.d.tsimportsDebouncedFuncin a type position@types/reactand@types/lodashare present only indevDependencies, so they are not part of the published contract.Under a hoisted
node_moduleslayout this resolves by accident, which is why it survives normal testing (andskipLibCheck: truehides the resulting errors inside the.d.ts). It does not resolve under pnpm's isolated linker with a global virtual store: each package is linked from a store path outside the consuming project, and TypeScript resolves a package's imports from where that package physically lives.reactthen resolves to the untypedreact/index.js, the editor component props degrade toany, and consumers building withnoImplicitAnyget errors like:Change
@types/reactand@types/lodashare added as optional peer dependencies ofslate-react. Optional matters: JavaScript-only consumers must not get an unmet-peer warning (verified withstrictPeerDependencies: trueand no@types/*installed).The ranges track majors and are deliberately open-ended at the top:
@types/reactmajors follow React majors, and the meaningful constraint is already carried by the existingreactpeer, so pinning an upper bound would only produce false unmet-peer failures the day@types/react20 ships.@types/lodashtracks lodash 4.x, matching thelodashdependency range. The shipped declarations were typechecked against@types/react17, 18 and 19 and are clean in all three.The existing
react,react-dom,slateandslate-domranges are unchanged. A patch changeset is included.No
@types/react-domentry:react-domis imported only for values (unstable_batchedUpdates,flushSync) and does not appear in any type position in the shipped declarations.@types/lodashis only reachable through a deep import today (slate-react/dist/hooks/android-input-manager/android-input-manager), since that module is not re-exported fromindex.d.ts. It is still a specifier appearing in a type position in a shipped.d.ts, and the package has noexportsmap, so deep imports are possible. An alternative worth considering separately is dropping theDebouncedFuncreference from that declaration in favour of a structural type, which would remove the requirement entirely.Sibling packages
The other packages in the monorepo were swept with the same rule — every specifier appearing in a type position in a shipped
.d.tsmust be declared — and all are already correct:dist/**/*.d.tsslateslate-domslateslate-historyslateslate-hyperscriptslateslate-reactreact,lodash,slate,slate-domslate/slate-domalready peers; the two@types/*entries are this PRVerification
All five packages were built and packed, and both a patched and an unpatched baseline
slate-reacttarball were installed into scratch consumers.enableGlobalVirtualStore: trueand avirtualStoreDiroutside the consumer, typechecking withskipLibCheck: falseandnoImplicitAny:TS7016forreactineditable.d.ts,element.d.ts,leaf.d.ts,text.d.tsand othersany:any.tsc --traceResolutionfromslate-react/dist/components/editable.d.ts:Module name 'react' was successfully resolved to '.../@types/react/index.d.ts'— a.d.ts, notreact/index.js.--install-strategy=nestedtypechecks cleanly both before and after, confirming that a hoisted layout forgives the missing declaration.attw --packreports "No problems found" for all five tarballs.publintreports no errors; the warnings it does emit are pre-existing and identical across all five packages (repositoryuses thegit://shorthand,dist/index.es.jsis ESM interpreted as CJS, noexportsmap) and are untouched here.Note on side findings
Two unrelated packaging observations surfaced during the sweep. Neither is addressed in this PR, since both are dependency removals with their own compatibility risk for anyone relying on the transitive install, and they are worth deciding on separately:
slate-domdeclares five dependencies that its bundle never requires:@juggle/resize-observer,direction,lodash,scroll-into-view-if-neededandis-plain-object. The built bundle only requiresis-hotkeyandslate.slate-reactdeclaresis-hotkeyandtiny-invariant, which its bundle likewise never requires.The
publintwarnings listed above are a third such finding: they affect every package equally and predate this change.🤖 Generated with Claude Code