Skip to content

Instantly share code, notes, and snippets.

@kouameYao
Last active May 31, 2024 17:28
Show Gist options
  • Save kouameYao/014636a122ca2558aa024bd5ab4b10a6 to your computer and use it in GitHub Desktop.
Save kouameYao/014636a122ca2558aa024bd5ab4b10a6 to your computer and use it in GitHub Desktop.
explore-more
export function enumToKeyValueArray<E extends Record<string, string | number>>(
  enumObj: E
): KeyValueEntry<keyof E, E[keyof E]>[] {
  return Object.entries(enumObj).map(([key, value]) => ({
    value: key as keyof E,
    label: value as E[keyof E],
  }));
}
interface MyParams {
  canDownload?: boolean;
  handleDownload?: () => void;
}

type RequireBothOrNone<T> = (T extends { paramA: infer A } ? A extends undefined
  ? {} : { paramB: string } : {})
  & (T extends { paramB: infer B } ? (B extends undefined ? {} : { paramA: string }) : {});

type LinkParams = MyParams & RequireBothOrNone<MyParams>;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment