Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type inference is not working when used with Enum #233

Open
hg-pyun opened this issue Sep 26, 2023 · 1 comment
Open

Type inference is not working when used with Enum #233

hg-pyun opened this issue Sep 26, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@hg-pyun
Copy link
Collaborator

hg-pyun commented Sep 26, 2023

Bug Report

💻 Code

https://codesandbox.io/s/competent-star-g4nqnp?file=/src/App.tsx

import { entries, fromEntries, groupBy, map, pipe, reduce } from "@fxts/core";
import "./styles.css";

type DataSet = {
  status: Status;
  count: number;
};

enum Status {
  Todo = "TODO",
  InProgress = "IN_PROGRESS",
  Done = "DONE"
}

const data: Array<DataSet> = [
  {
    status: Status.Todo,
    count: 0
  },
  {
    status: Status.InProgress,
    count: 0
  }
];

export default function App() {
  pipe(
    data,
    map((item) => {
      return {
        progress: Status.Done,
        count: item.count
      };
    }),
    groupBy((item) => item.progress),
    entries,
    map(([progress, values]) => {
      return [
        progress,
        reduce((acc, cur) => acc + cur.count, 0, values) // <-- Type Error: values
      ] as const;
    }),
    fromEntries
  );

  return null;
}

🙁 Actual behavior

TypeScript Inference is not working.

🙂 Expected behavior

TypeScript Inference works.


Version Information

@fxts/[email protected]: fine.
@fxts/[email protected]: bug occur.

Maybe #199 side effect.

@hg-pyun hg-pyun changed the title Type inference is not working when used with Enum. Type inference is not working when used with Enum Sep 26, 2023
@ppeeou ppeeou added the bug Something isn't working label Sep 26, 2023
@ppeeou
Copy link
Member

ppeeou commented Sep 27, 2023

@hg-pyun

First If you change the function which inner reduce below, you can use it.
but I think improvement is needed.

reduce((acc:number, cur:{count:number}) => acc + cur.count, 0, values) 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants