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

feat: enhance entries type #230

Closed
ppeeou opened this issue Sep 25, 2023 · 1 comment · Fixed by #231
Closed

feat: enhance entries type #230

ppeeou opened this issue Sep 25, 2023 · 1 comment · Fixed by #231
Assignees
Labels
enhancement New feature or request

Comments

@ppeeou
Copy link
Member

ppeeou commented Sep 25, 2023

Suggestion

⭐ Suggestion

entries type is supported to fit more general situations.

💻 Use Cases

type Obj = {
  [key: string]: number;
};

const fn = (obj: Obj) => entries(obj);
const res1 = fn({ hello: 3 }); //  Generator<[string, number], void, unknown

const res2 = entries({ hello: 2 }); // Generator<["hello", number], void, unknown>


export const OsTypeEnum = {
  Android: `android`,
  Ios: `ios`,
  Windows: `windows`,
} as const;

export type OsTypeEnum = (typeof OsTypeEnum)[keyof typeof OsTypeEnum];
type Os = {
  [key in OsTypeEnum]: string;
};

const fn = (obj: Os) => entries(obj);
const res4 = fn({
  [OsTypeEnum.Android]: "Android",
  [OsTypeEnum.Ios]: "Ios",
  [OsTypeEnum.Windows]: "Windows",
  // only OsTypeEnum key
});
@ppeeou ppeeou added the enhancement New feature or request label Sep 25, 2023
@ppeeou ppeeou self-assigned this Sep 25, 2023
@ppeeou
Copy link
Member Author

ppeeou commented Sep 25, 2023

@mkitwave Thank you for your report 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant