If I create a custom type such as:
type LowercaseString = string
And then use it in a function like this:
function displayLowercaseString(input: LowercaseString) {
...
}
displayLowercaseString('UPPERCASE')
The above example compiles perfectly and runs, since 'UPPERCASE' is of type string and so is LowercaseString
My question is, is it possible to have a TS error such as
type string does not match LowercaseString
so that I am forced to put every string through a function like this before using it in displayLowercaseString:
function stringToLowercase(input: string): LowercaseString {
return input.toLowercase as LowercaseString
}
type ID = numberis another example, where I wouldn't want a function that accepts typeIDto just accept any number. It should only accept variables with the typeID