Is there a way to retrieve the string representation of a type name in order to return a more concise compile error message from a type function?
I came across this solution (unfortunately, the article does not have anchor links so you will need to search for ErrorBrand) that demonstrates how to create an error message. Can we achieve the following using this method:
type ErrorBrand<Err extends string> = Readonly<{
[k in Err]: void;
}>;
type MyErrorMsgType<T extends string> = ErrorBrand<`The following type caused an error - ${T}`>
type MyType = {field:string};
type GetStringNameOfType<T> = // converts Type to string name of type
type MyTypeName = GetStringNameOfType<MyType> // outputs 'MyType'
type MyTypeError = MyErrorMsgType<MyTypeName>
// output - The following type caused an error - MyType