Repository navigation
fix: type curried recipes whose draft is annotated with a type parameter - #204
Merged
Merged
Conversation
|
Coverage after merging fix/curried-recipes-of-type-parameters into main will be
Coverage Report
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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
mainand npm 1.3.0create(async (draft: T) => { … })infunction update<T extends object>()[draft, finalize], so calling the producer does not compile ("This expression is not callable", TS2349); the same for synchronous recipes, recipes that return a new state and recipes with arguments, while the call returns a producer at run time(base: T) => T, or(base: T) => Promise<T>for an async recipe, with the arguments of the recipeThe overload that infers the state type of a curried producer takes a recipe typed
(draft: Draft<T>, ...args: P) => R, and TypeScript cannot match a draft typed as a type parameter againstDraft<T>, so the overload of a manual draft accepts the recipe as the base state. Direct calls already have an overload for a draft typed as the state itself,(base: T, mutate: (draft: T) => R); this PR adds its curried counterpart. Annotating the draft asDraft<T>worked before and still does.Changes, one commit per item
fix: type a curried recipe whose draft is annotated with a type parameter: the curried overload for a draft typed as the state, after the one that takesDraft<T>. A type test covers synchronous and async recipes, a recipe with an argument and one that returns a new state, and checks their results at run time.docs: describe curried recipes whose draft is annotated with a type parameter: the migration guide in the README and on the website, and the advice for generic code under async recipes in the README and on thecreate()page, which now shows the curried form as well.docs: regenerate the API reference: the new signature ofcreate()andmakeCreator(); the links point to the commit before it.Behavior changes to review
Verification
mainwith eight errors: four type assertions and four calls of a value without a call signature.main(7,482, 12,219 and 11,840); generic factories whose draft is typedTtake 17,397 instead of 17,576 and now give producers.size:compareare 0); the declaration ofmakeCreatorgrows from 4,554 B to 4,829 B.test:benchmarks,size,test:packagewith its TypeScript 5.0 consumer,test:build-watch,type-checkand 5,041 tests.Not covered
create<T>(async (draft) => { … }), still gives(base: T) => T, as docs: name the state types that keep async results typed as the state, fix the JSON Patch note and state the TypeScript versions #203 documents;create(async (draft: T) => { … })is the curried form that gives a Promise.