Last active
October 19, 2021 19:28
-
-
Save mateja176/df3d0d0e51e0eb04e9ee309c868facae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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