Not sure if this is possible or to best describe this, but I need to infer the literal type of a type that's already defined by another type/interface.
For example, I've got an object that adheres to a certain interface:
interface MyObject {
foo: string | number;
bar: string[];
}
const MY_OBJECT: MyObject = {
foo: 123,
bar: ["abc", "def"],
};
Now, what I'd like to know is the type literal of MY_OBJECT
, by doing something like this:
type MyObjectLiteral = Infer<typeof MY_OBJECT>;
That should make MyObjectLiteral
: { foo: 123, bar: ["abc", "def"] }
The question is how to define type Infer<T>
to return the inferred type of T
.
Any help or clarification would be appreciated.