Skip to content

Commit

Permalink
fix: pipe return type (#259)
Browse files Browse the repository at this point in the history
  • Loading branch information
ppeeou authored Mar 20, 2024
1 parent 208e0dd commit 8558e31
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/types/ReturnPipeType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type HasPromise<T extends any[]> = Head<T> extends never

type PossiblyHasPromise<T extends any[]> = Head<T> extends never
? false
: Equals<Head<T>, Head<T> | Promise<Awaited<Head<T>>>> extends 1
: Equals<Head<T> | Promise<Awaited<Head<T>>>, Head<T>> extends 1
? true
: T["length"] extends 0
? false
Expand Down
33 changes: 32 additions & 1 deletion type-check/pipe.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { pipe, throwError } from "../src";
import { entries, filter, map, pipe, throwError, toArray } from "../src";
import * as Test from "../src/types/Test";

const { checks, check } = Test;
Expand Down Expand Up @@ -144,6 +144,36 @@ const res19 = pipe(
async (_: { code: Code }): Promise<Code> => Code.None,
);

interface Data {
a?: {
value: string;
order: string;
};
b?: {
value: string;
order: string;
};
}

const data: Data = {
a: {
value: "a",
order: "1",
},
b: {
value: "b",
order: "2",
},
};

const res20 = pipe(
data,
entries,
filter(([, value]) => value != null),
map(([key]) => key),
toArray,
);

checks([
check<typeof res1, string, Test.Pass>(),
check<typeof res2, number, Test.Pass>(),
Expand All @@ -164,4 +194,5 @@ checks([
check<typeof res17, Promise<never>, Test.Pass>(),
check<typeof res18, Code, Test.Pass>(),
check<typeof res19, Promise<Code>, Test.Pass>(),
check<typeof res20, ("a" | "b")[], Test.Pass>(),
]);

0 comments on commit 8558e31

Please sign in to comment.