Repository: marpple/FxTS (ts)

Issue:
"Type instantiation is excessively deep and possibly infinite" error with large Enum values.
# Bug Report

<!--
  Please fill in each section completely. Thank you!
-->

Using a large number of enum results in an error. 

### 💻 Code

<!-- Please post the relevant code sample here as well-->
<!-- How to reproduce it -->

https://codesandbox.io/s/eager-frost-69nrn9?file=/src/App.tsx:0-751

```ts
import { pipe, find } from "@fxts/core";

export default function App() {
  return null;
}

enum Code {
  _1,
  _2,
  _3,
  _4,
  _5,
  _6,
  _7,
  _8,
  _9,
  _10,
  _11,
  _12,
  _13,
  _14,
  _15,
  _16,
  _17,
  _18,
  _19,
  _20,
  _21,
  _22,
  _23,
  _24,
  _25,
  _26,
  _27,
  _28,
  _29,
  _30,
  _31,
  _32,
  _33,
  _34,
  _35,
  _36,
  _37,
  _38,
  _39,
  _40,
  _41,
  _42,
  _43,
  _44,
  _45,
  _46,
  _47,
  _48,
  _49,
  _50,
  _51,
  _52,
  _53,
  _54,
  _55,
  _56,
  _57,
  _58,
  _59,
  _60
}

type data = {
  code: Code;
};

function errorCode(arr: Array<data>, getData: (arr: data) => Code) {
  return pipe(
    arr,
    find((obj) => pipe(obj, getData)), // Type instantiation is excessively deep and possibly infinite.
    (data) => (data !== undefined ? getData(data) : undefined)
  );
}

```

### 🙁 Actual behavior

"Type instantiation is excessively deep and possibly infinite" Error occur.

### 🙂 Expected behavior

No Type Error.

---

### Version Information

<!-- Please let me know your environment -->

- @fxts/core: 0.21.0
- Typescript: 5.2.2 


Pull request:
fix: pipe return type
Fixes #234


Patch:
diff --git a/src/types/ReturnPipeType.ts b/src/types/ReturnPipeType.ts
index 0613bc10..fb8aca27 100644
--- a/src/types/ReturnPipeType.ts
+++ b/src/types/ReturnPipeType.ts
@@ -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


Test patch:
diff --git a/type-check/pipe.test.ts b/type-check/pipe.test.ts
index 59a5934e..0b123656 100644
--- a/type-check/pipe.test.ts
+++ b/type-check/pipe.test.ts
@@ -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;
@@ -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>(),
@@ -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>(),
 ]);