If what you want is infer the type from the expression, typeof is your friend:
const value = {
foo: "alpha",
bravo: "bravo"
};
type Type = typeof value;
That will give you a type like:
type Type = {
foo: string;
bravo: string;
};
If you need to infer the every value type as a literal you can do something like:
const value = {
foo: "alpha",
bravo: "bravo"
} as const;
type Type = typeof value;
Now Type will be:
type Type = {
readonly foo: "alpha";
readonly bravo: "bravo";
};
If you don't want the properties as readonly you can do:
const value = {
foo: "alpha" as const,
bravo: "bravo" as const
};
type Type = typeof value;
And Type will be:
type Type = {
foo: "alpha";
bravo: "bravo";
};