marpple / FxTS

A functional programming library for TypeScript/JavaScript
https://fxts.dev
Apache License 2.0
862 stars 63 forks source link

"Type instantiation is excessively deep and possibly infinite" error with large Enum values. #234

Closed hg-pyun closed 4 months ago

hg-pyun commented 9 months ago

Bug Report

Using a large number of enum results in an error.

💻 Code

https://codesandbox.io/s/eager-frost-69nrn9?file=/src/App.tsx:0-751

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

ppeeou commented 4 months ago

@hg-pyun Thank you for reporting the error. Issue resolved in 0.27.0 :)