I'm using a named type in my typescript file like so:
type VersionNumber =
| `${number}`
| `${number}.${number}`
| `${number}.${number}.${number}`
| `${number}.${number}.${number}.${string}`;
type Example = {
id:string
version:VersionNumber
}
let example:exmaple = {
id:'some.id',
version:['1.2'] // Type 'string[]' is not assignable to type 'VersionNumber'.
}
Type '
string[]' is not assignable to type 'VersionNumber'.
I find this very unhelpful because it doesn't even start to describe the definition of what VersionNumber type is. The issue is that I find it very overwhelming to use the full type definition of VersionNumber instead of the name. I could also endup reusing the type and that would mean duplicated code.
type Example = {
id:string
version:
| `${number}`
| `${number}.${number}`
| `${number}.${number}.${number}`
| `${number}.${number}.${number}.${string}`;
}
let example:exmaple = {
id:'some.id',
version:['1.2']
}
But that will change the error prompt to:
Type '
string[]' is not assignable to type '${number}|${number}.${number}|${number}.${number}.${number}|${number}.${number}.${number}.${string}'.
Which is much more helpful to me.
Is there a way to always display the named type definition? I know that if the named type definition is simple, it will be displayed, but not with complex types with | or complex objects.