objectFromEntries
Like Object.fromEntries() but with a better return type
Functionally identical to Object.fromEntries()
but instead of returning but its return type more precise than just { [k: sting]: any; }
.
import { assert, type Equals, objectFromEntries } from "tsafe";
const entries = [
["a", "foo"],
["b", 33],
["c", true as boolean],
] as const;
const obj = objectFromEntries(entries);
// ^ obj is of type { a: "foo"; b: 33; c: boolean; }
assert<
Equals<
typeof obj,
{
a: "foo";
b: 33;
c: boolean;
}
>
>;
Last updated
Was this helpful?