How do I create a type helper that will deeply convert any value types that are string literal unions to mere string types? Here's my attempt:
type GenericStringType<T> =
number | undefined | null | symbol | BigInt extends T
? T
: string extends T
? T & string
: { [P in keyof T]: GenericStringType<T[P]> }
I know this isn't right, and there's some better way to do the "early exit condition" so as to not have infinite recursion through non-object types, but I don't know what that is.
As an example:
const x = { a: 'value' } as const
const y = { a: 'anotherValue' } satisfies GenericStringType<typeof x>
So that y must have the exact same structure as x, both x and y are const types that have specific string literal values, but we can be sure that y and x are exactly compatible for properties and structure, assuming all string values are compared as strings and not as consts.