Skip to content

Instantly share code, notes, and snippets.

@mateja176
Last active October 19, 2021 19:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mateja176/df3d0d0e51e0eb04e9ee309c868facae to your computer and use it in GitHub Desktop.
Save mateja176/df3d0d0e51e0eb04e9ee309c868facae to your computer and use it in GitHub Desktop.
type A = { a: 1; b: 2 };
type ObjectToArray<O> = {
[Key in keyof O]: [Key, O[Key]];
}[keyof O][];
type B = ObjectToArray<A>;
const entries = <O>(o: O): ObjectToArray<O> => {
const a: ObjectToArray<O> = [];
for (const key in o) {
const element = o[key];
a.push([key, element]);
}
return a;
};
const a: A = {
a: 1,
b: 2,
}
const b = entries(a);
type C = typeof b
type D = C[number]
type E = D[0]
type F = D[1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment