(and OrderedEntriesOf
?)
OrderedKeysOf<typeof x>
would be the exact ordered type of Object.keys(x)
and OrderedValuesOf<typeof x>
the exact ordered type of Object.values(x)
.
const SYMBOL = Symbol("hi")
interface X {
a: number,
b: "cd",
c: boolean,
d: {x: number},
e: null,
[SYMBOL]: "f"
}
// Satisfies X but with reversed declaration order
const x = {
[SYMBOL]: "f",
e: null,
d: {x: 1},
c: false,
b: "cd",
a: 0,
} satisfies X;
type K = OrderedKeys<typeof x> // [typeof SYMBOL, "e", "d", "c", "b", "a"]
type V = OrderedValues<typeof x> // ["f", null, { x: number; }, false, "cd", number]
Under the hood, it uses UnionToTuple
which is more controversial / flaky (see #534). Here we only use it on the keys of an object, a union of string
& Symbol
without repeating values.
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too