test(ts): fix for latest commit
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by aleclarson · committed by aleclarson · parent 03ec620 · Browse files · 1 file·+25 added−39 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+25 added−39 removed
- tests:+25 added−39 removed
Provenance
- Commit
ee8aac0- Tree
3de3b73- Author
aleclarson <alec.stanford.larson@gmail.com>- Committer
aleclarson <alec.stanford.larson@gmail.com>- Parent
03ec620
1 file changed+25 added−39 removed
modified:__tests__/produce.ts+25 added-39 removed
12345675678958 unmodified lines68697071747576727374757677788384858687798081828391928485868796888990919241 unmodified lines13413513613714614714814915015115215315413813914014114214314415615715815916016116216316416514514614714814915015116716816915215315415517117217315615715815916016116216326 unmodified linesimport produce, { produce as produce2, applyPatches, Patch, nothing, Draft, Immutable nothing} from "../dist/immer.js"
// prettier-ignoretype Exact<A, B> = (<T>() => T extends A ? 1 : 0) extends (<T>() => T extends B ? 1 : 0)58 unmodified lines})
// NOTE: only when the function type is inferredit("can infer state type from default state", () => { type Producer = <T>( base: (Draft<T> extends number ? T : number) | undefined ) => Immutable<T> type Producer = (base: number | undefined) => number let foo = produce(_ => {}, 1) exactType(foo, {} as Producer) exactType(foo(2), 0 as number)})
it("can infer state type from recipe function", () => { type Base = string | number type Producer = <T>( base: (Draft<T> extends Base ? T : Base) | undefined, _2: number ) => Immutable<T> type T = string | number type Producer = (base: T | undefined, _2: number) => T
let foo = produce((_: string | number, _2: number) => {}, 1) exactType(foo, {} as Producer) exactType(foo("", 0), {} as string) exactType(foo(0, 0), {} as number) exactType(foo("", 0), {} as string | number)})
it("cannot infer state type when the function type and default state are missing", () => { exactType(produce(_ => {}), {} as <T>(base: T) => any) exactType(produce(_ => {}), {} as (base: any) => any)})
it("can update readonly state via curried api", () => { const newState = produce<State>(draft => {41 unmodified lines
expect(applyPatches({}, patches)).toEqual({x: 4})})
it("can provide rest parameters to a curried producer", () => { type Foo = <T>( base: Draft<T> extends {} ? T : object, _2: number, _3: number ) => Immutable<T> let foo = produce((_1: object, _2: number, _3: number) => {}) exactType(foo, {} as Foo) foo({}, 1, 2)describe("curried producer", () => { it("supports rest parameters", () => { type Foo = (base: {}, _2: number, _3: number) => {} let foo = produce((_1: {}, _2: number, _3: number) => {}) exactType(foo, {} as Foo) foo({}, 1, 2)
// With initial state: type Bar = <T>( base: (Draft<T> extends {} ? T : object) | undefined, _2: number, _3: number ) => Immutable<T> let bar = produce((_1: object, _2: number, _3: number) => {}, {}) exactType(bar, {} as Bar) bar(undefined, 1, 2)}) // With initial state: type Bar = (base: {} | undefined, _2: number, _3: number) => {} let bar = produce((_1: {}, _2: number, _3: number) => {}, {}) exactType(bar, {} as Bar) bar(undefined, 1, 2) })
it("can pass readonly arrays to curried producers", () => { let foo = produce((_: any[]) => {}) foo([] as ReadonlyArray<any>) it("can be passed a readonly array", () => { let foo = produce((_: any[]) => {}) foo([] as ReadonlyArray<any>)
// With initial state: let bar = produce((_: any[]) => {}, []) bar([] as ReadonlyArray<any>) // With initial state: let bar = produce((_: any[]) => {}, []) bar([] as ReadonlyArray<any>) })})
it("always returns an immutable type", () => { let result = produce([] as any[], () => {})26 unmodified lines