Is there a way in Typescript to convert union member to string?
Like following:
type T = TObjectA | TObjectB
// use somewhere as string literal union:
type TAsString = "TObjectA" | "TObjectB"
Simplified example of actual intent:
import type { user, address, invoice } from "@/db-codegen"
type TModel = user | address | invoice
type MyProps = {
model: TModel
// This obviously wont't work. So as .toString() and other naive attempts
modelName: `${TModel}`
// desired outcome: "user" | "address" | "invoice"
}
This is probably a duplicate of TypeScript: Getting names (as string) of Union's possible types?, but it has only one – and not really satisfactory – answer.
I was hoping this thread String Union to string Array could help, but it probably addresses a slightly different problem.
Thanks a lot.