objectEntries
Like Object.entries() but with a better return type.
Functionally equal to
Object.entries
but features a return type more precise than just [string, T][].
import { assert, Equals } from "tsafe";
import { objectEntries } from "tsafe/objectEntries";
// v entries is of type ["a", string], ["b", number], ["c", boolean]
const entries = objectEntries({
a: "foo",
b: 33,
c: true,
});
assert<
Equals<typeof entries, (["a", string] | ["b", number] | ["c", boolean])[]>
>();
Last modified 4mo ago