diff --git a/src/Lazy/pipeLazy.ts b/src/Lazy/pipeLazy.ts index 3b746fa6..2f78d8fc 100644 --- a/src/Lazy/pipeLazy.ts +++ b/src/Lazy/pipeLazy.ts @@ -48,26 +48,26 @@ import type ReturnPipeType from "../types/ReturnPipeType"; // prettier-ignore function pipeLazy( f1: (a: Awaited) => R -): (a: T1) => ReturnPipeType<[T1,R]>; +): (a: T1 | Promise) => ReturnPipeType<[T1,R]>; // prettier-ignore function pipeLazy( f1: (a: Awaited) => T2, f2: (a: Awaited) => R -): (a: T1) => ReturnPipeType<[T1, T2, R]>; +): (a: T1 | Promise) => ReturnPipeType<[T1, T2, R]>; function pipeLazy( f1: (a: Awaited) => T2, f2: (a: Awaited) => T3, f3: (a: Awaited) => R, -): (a: T1) => ReturnPipeType<[T1, T2, T3, R]>; +): (a: T1 | Promise) => ReturnPipeType<[T1, T2, T3, R]>; function pipeLazy( f1: (a: Awaited) => T2, f2: (a: Awaited) => T3, f3: (a: Awaited) => T4, f4: (a: Awaited) => R, -): (a: T1) => ReturnPipeType<[T1, T2, T3, T4, R]>; +): (a: T1 | Promise) => ReturnPipeType<[T1, T2, T3, T4, R]>; function pipeLazy( f1: (a: Awaited) => T2, @@ -75,7 +75,7 @@ function pipeLazy( f3: (a: Awaited) => T4, f4: (a: Awaited) => T5, f5: (a: Awaited) => R, -): (a: T1) => ReturnPipeType<[T1, T2, T3, T4, T5, R]>; +): (a: T1 | Promise) => ReturnPipeType<[T1, T2, T3, T4, T5, R]>; function pipeLazy( f1: (a: Awaited) => T2, @@ -84,7 +84,7 @@ function pipeLazy( f4: (a: Awaited) => T5, f5: (a: Awaited) => T6, f6: (a: Awaited) => R, -): (a: T1) => ReturnPipeType<[T1, T2, T3, T4, T5, T6, R]>; +): (a: T1 | Promise) => ReturnPipeType<[T1, T2, T3, T4, T5, T6, R]>; function pipeLazy( f1: (a: Awaited) => T2, @@ -94,7 +94,7 @@ function pipeLazy( f5: (a: Awaited) => T6, f6: (a: Awaited) => T7, f7: (a: Awaited) => R, -): (a: T1) => ReturnPipeType<[T1, T2, T3, T4, T5, T6, T7, R]>; +): (a: T1 | Promise) => ReturnPipeType<[T1, T2, T3, T4, T5, T6, T7, R]>; function pipeLazy( f1: (a: Awaited) => T2, @@ -105,8 +105,9 @@ function pipeLazy( f6: (a: Awaited) => T7, f7: (a: Awaited) => T8, f8: (a: Awaited) => R, -): (a: T1) => ReturnPipeType<[T1, T2, T3, T4, T5, T6, T7, T8, R]>; +): (a: T1 | Promise) => ReturnPipeType<[T1, T2, T3, T4, T5, T6, T7, T8, R]>; +// prettier-ignore function pipeLazy( f1: (a: Awaited) => T2, f2: (a: Awaited) => T3, @@ -117,8 +118,9 @@ function pipeLazy( f7: (a: Awaited) => T8, f8: (a: Awaited) => T9, f9: (a: Awaited) => R, -): (a: T1) => ReturnPipeType<[T1, T2, T3, T4, T5, T6, T7, T8, T9, R]>; +): (a: T1 | Promise) => ReturnPipeType<[T1, T2, T3, T4, T5, T6, T7, T8, T9, R]>; +// prettier-ignore function pipeLazy( f1: (a: Awaited) => T2, f2: (a: Awaited) => T3, @@ -130,8 +132,9 @@ function pipeLazy( f8: (a: Awaited) => T9, f9: (a: Awaited) => T10, f10: (a: Awaited) => R, -): (a: T1) => ReturnPipeType<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, R]>; +): (a: T1 | Promise) => ReturnPipeType<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, R]>; +// prettier-ignore function pipeLazy( f1: (a: Awaited) => T2, f2: (a: Awaited) => T3, @@ -144,8 +147,9 @@ function pipeLazy( f9: (a: Awaited) => T10, f10: (a: Awaited) => T11, f11: (a: Awaited) => R, -): (a: T1) => ReturnPipeType<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, R]>; +): (a: T1 | Promise) => ReturnPipeType<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, R]>; +// prettier-ignore function pipeLazy( f1: (a: Awaited) => T2, f2: (a: Awaited) => T3, @@ -159,8 +163,9 @@ function pipeLazy( f10: (a: Awaited) => T11, f11: (a: Awaited) => T12, f12: (a: Awaited) => R, -): () => ReturnPipeType<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, R]>; +): (a: T1 | Promise) => ReturnPipeType<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, R]>; +// prettier-ignore function pipeLazy( f1: (a: Awaited) => T2, f2: (a: Awaited) => T3, @@ -175,9 +180,7 @@ function pipeLazy( f11: (a: Awaited) => T12, f12: (a: Awaited) => T13, f13: (a: Awaited) => R, -): () => ReturnPipeType< - [T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, R] ->; +): (a: T1 | Promise) => ReturnPipeType<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, R]>; // prettier-ignore function pipeLazy( @@ -195,7 +198,7 @@ function pipeLazy) => T13, f13: (a: Awaited) => T14, f14: (a: Awaited) => R, -): (a: T1) => ReturnPipeType<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, R]>; +): (a: T1 | Promise) => ReturnPipeType<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, R]>; // prettier-ignore function pipeLazy( @@ -214,7 +217,7 @@ function pipeLazy) => T14, f14: (a: Awaited) => T15, f15: (a: Awaited) => R, -): (a: T1) => ReturnPipeType<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, R]>; +): (a: T1 | Promise) => ReturnPipeType<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, R]>; // prettier-ignore function pipeLazy( @@ -234,7 +237,7 @@ function pipeLazy) => T15, f15: (a: Awaited) => T16, f16: (a: Awaited) => R, -): (a: T1) => ReturnPipeType<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, R]>; +): (a: T1 | Promise) => ReturnPipeType<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, R]>; // prettier-ignore function pipeLazy( @@ -255,7 +258,7 @@ function pipeLazy) => T16, f16: (a: Awaited) => T17, f17: (a: Awaited) => R, -): (a: T1) => ReturnPipeType<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, R]>; +): (a: T1 | Promise) => ReturnPipeType<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, R]>; // prettier-ignore function pipeLazy( @@ -277,7 +280,7 @@ function pipeLazy) => T17, f17: (a: Awaited) => T18, f18: (a: Awaited) => R, -): (a: T1) => ReturnPipeType<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, R]>; +): (a: T1 | Promise) => ReturnPipeType<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, R]>; // prettier-ignore function pipeLazy( @@ -300,7 +303,7 @@ function pipeLazy) => T18, f18: (a: Awaited) => T19, f19: (a: Awaited) => R, -): (a: T1) => ReturnPipeType<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, R]>; +): (a: T1 | Promise) => ReturnPipeType<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, R]>; // prettier-ignore function pipeLazy( @@ -324,7 +327,7 @@ function pipeLazy) => T19, f19: (a: Awaited) => T20, f20: (a: Awaited) => R, -): (a: T1) => ReturnPipeType<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, R]>; +): (a: T1 | Promise) => ReturnPipeType<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, R]>; function pipeLazy(...fns: any[]) { return (a: any) => reduce(pipe1, a, fns); diff --git a/type-check/Lazy/pipeLazy.test.ts b/type-check/Lazy/pipeLazy.test.ts new file mode 100644 index 00000000..e5510662 --- /dev/null +++ b/type-check/Lazy/pipeLazy.test.ts @@ -0,0 +1,83 @@ +import { pipeLazy, throwError } from "../../src"; +import * as Test from "../../src/types/Test"; + +const { checks, check } = Test; + +const res1 = pipeLazy(String)(1); +const res2 = pipeLazy(Number)("1"); + +const res3 = pipeLazy(async (n: number) => String(n))(Promise.resolve(1)); +const res4 = pipeLazy(async (s: string) => Number(s))(Promise.resolve("1")); + +const res5 = pipeLazy((a) => Promise.resolve(String(a)))(1); +const res6 = pipeLazy((a) => Promise.resolve(Number(a)))("1"); + +const res7 = pipeLazy((a) => Promise.resolve(String(a)))(Promise.resolve(1)); +const res8 = pipeLazy((a) => Promise.resolve(Number(a)))(Promise.resolve("1")); + +const res9 = pipeLazy( + (a: "a" | "b") => a.toUpperCase(), + () => 1, +)("a"); + +const res10 = pipeLazy( + (a: "a") => a.toUpperCase(), + async () => 1, +)(Promise.resolve("a")); + +const res11 = pipeLazy( + (a: "a") => Promise.resolve(a.toUpperCase()), + () => 1, +)(Promise.resolve("a")); + +const res12 = pipeLazy( + (a: "a") => a.toUpperCase(), + () => Promise.resolve(1), +)(Promise.resolve("a")); + +const res13 = pipeLazy( + (a: "a") => (Math.random() > 0.5 ? a.toUpperCase() : Promise.resolve("hi")), + () => 1, +)(Promise.resolve("a")); + +const res14 = pipeLazy(throwError(() => Error()))(0); + +const res15 = pipeLazy( + async () => 1, + throwError(() => Error()), +)(0); + +const res16 = pipeLazy( + throwError(() => Error()), + async () => 1, + () => 2, +)(0); + +const res17 = pipeLazy( + async () => { + throw Error(""); + }, + throwError(() => Error("")), + () => 1, + () => 2, +)(0); + +checks([ + check(), + check(), + check, Test.Pass>(), + check, Test.Pass>(), + check, Test.Pass>(), + check, Test.Pass>(), + check, Test.Pass>(), + check, Test.Pass>(), + check(), + check, Test.Pass>(), + check, Test.Pass>(), + check, Test.Pass>(), + check, Test.Pass>(), + check(), + check, Test.Pass>(), + check(), + check, Test.Pass>(), +]);