Skip to content

Commit

Permalink
fix: type instantiation is excessively deep and possibly infinite in …
Browse files Browse the repository at this point in the history
…pipe
  • Loading branch information
ppeeou committed Mar 19, 2024
1 parent 30f27f1 commit b83d8f3
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/types/ReturnPipeType.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type Awaited from "./Awaited";
import type { TuplifyUnion } from "./ExcludeObject";
import type Equals from "./Equals";
import type Head from "./Head";
import type Tail from "./Tail";

Expand All @@ -13,7 +13,7 @@ type HasPromise<T extends any[]> = Head<T> extends never

type PossiblyHasPromise<T extends any[]> = Head<T> extends never
? false
: HasPromise<TuplifyUnion<Head<T>>> extends true
: Equals<Head<T>, Head<T> | Promise<Awaited<Head<T>>>> extends 1
? true
: T["length"] extends 0
? false
Expand Down
73 changes: 73 additions & 0 deletions type-check/pipe.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,77 @@ const res17 = pipe(
() => 2,
);

const Code = {
None: "NONE",
_00: "00",
_11: "11",
_13: "13",
_15: "15",
_17: "17",
_19: "19",
_21: "21",
_23: "23",
_25: "25",
_27: "27",
_29: "29",
_32: "32",
_34: "34",
_41: "41",
_43: "43",
_46: "46",
_52: "52",
_54: "54",
_56: "56",
_58: "58",
_62: "62",
_64: "64",
_66: "66",
_68: "68",
_72: "72",
_81: "81",
_83: "83",
_85: "85",
_96: "96",
_10: "10",
_12: "12",
_14: "14",
_16: "16",
_18: "18",
_20: "20",
_22: "22",
_24: "24",
_26: "26",
_28: "28",
_31: "31",
_33: "33",
_36: "36",
_42: "42",
_44: "44",
_51: "51",
_53: "53",
_55: "55",
_57: "57",
_61: "61",
_63: "63",
_65: "65",
_67: "67",
_71: "71",
_73: "73",
_74: "74",
_75: "75",
_76: "76",
_82: "82",
_84: "84",
_95: "95",
} as const;

type Code = (typeof Code)[keyof typeof Code];
const res18 = pipe({ code: Code.None }, (_: { code: Code }): Code => Code.None);

Check warning on line 141 in type-check/pipe.test.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'_' is defined but never used
const res19 = pipe(
{ code: Code.None },
async (_: { code: Code }): Promise<Code> => Code.None,

Check warning on line 144 in type-check/pipe.test.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'_' is defined but never used
);

checks([
check<typeof res1, string, Test.Pass>(),
check<typeof res2, number, Test.Pass>(),
Expand All @@ -91,4 +162,6 @@ checks([
check<typeof res15, Promise<never>, Test.Pass>(),
check<typeof res16, never, Test.Pass>(),
check<typeof res17, Promise<never>, Test.Pass>(),
check<typeof res18, Code, Test.Pass>(),
check<typeof res19, Promise<Code>, Test.Pass>(),
]);

0 comments on commit b83d8f3

Please sign in to comment.