Repository navigation
docs: name the state types that keep async results typed as the state, fix the JSON Patch note and state the TypeScript versions - #203
Merged
Conversation
|
Coverage after merging docs/explicit-state-types-and-patch-notes into main will be
Coverage Report
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Coverage after merging docs/explicit-state-types-and-patch-notes into main will be
Coverage Report
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
This was referenced Oct 11, 2026
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.
Part of #168.
Summary
Three documentation fixes, with no change to the code or the types.
maincreate()page and the migration guide say that an explicit state type with an async recipe givesPromise<State>. That holds for concrete state types since #201, but a type parameter, as increate<T>(base, async (draft) => { … })in a generic function, or a state type that includes Promises, such asobjectorunknown, still gives the state type, as in 1.3.0, also for recipes that may return a Promise. The call returns a Promise.Promise<T>create()page and the Patches guide say that patches are fully compatible with JSON Patch whenarrayLengthAssignmentisfalse, although JSON Patch paths are stringspathAsArrayandarrayLengthAssignmentarefalse, as the "JSON Patch" bullet of the Patches guide already saysChanges, one commit per item
docs: name the explicit state types that keep async results typed as the state(item 1): the paragraph on async recipes in the README and on thecreate()page, and the first TypeScript bullet of the migration guide in the README and on the website.docs: state that JSON Patch compatibility also needs string paths(item 2): the README, thecreate()page and the Patches guide.docs: state the TypeScript versions that the types support(item 3): "Using TypeScript" in the README and the TypeScript guide.Verification
Item 1, with TypeScript 5.8.3 and the declarations built from
mainat09ab87b; npm 1.3.0 gives the same types:create<T>(base, async () => {})infunction f<T extends object>(base: T)T(draft) => void | Promise<void>, or curried,create<T>(async () => {})T,(base: T) => Tcreate<object>(…)orcreate<unknown>(…)with an async recipe or one that may return a Promiseobject,unknowncreate(base, async (draft) => { … })in the same generic functionPromise<T>create(async (draft: Draft<T>) => {})in a generic function(base: T) => Promise<T>Item 3:
pnpm test:packagecompiles a consumer of the packed package with TypeScript 5.0.4.The branch merges with fix: bound the search for repeated moved array elements and type maybe-async recipes of primitive states #202, which edits nearby lines of the README, the
create()page and the migration guide, without conflicts.Not covered
voidrecipe return. An extra overload for async recipes with the same base type changed no type in the full overload set, andNoInferneeds TypeScript 5.4. Two other changes were tried on fix: bound the search for repeated moved array elements and type maybe-async recipes of primitive states #202: async overloads with a plain base type before the overloads that infer the state type fix these calls, but also changed 10 of the other 152 types that the probes check in TypeScript 5.0.4–5.9.3, such ascreate(state, (draft) => { draft.count++; }), typedDraftedObject<State>without strict mode, andcreate(0, (n) => n + 1), rejected in strict mode; giving the inferring overloads aneverreturn by default broke five existing type checks, among them recipes typedanyand generic helpers whose recipes take(draft: T) => T. So these limits are documented instead.