If I define a custom type like this:
type SmallCapsString = string
And then utilize it in a function as shown below:
function displaySmallCapsString(input: SmallCapsString) {
...
}
displaySmallCapsString('UPPERCASE')
The code above compiles without issues and runs successfully, because 'UPPERCASE'
is of type string
, which matches SmallCapsString
I am wondering if there is a way to trigger a TypeScript error that says
type string does not match SmallCapsString
This would require me to convert every string input using a function similar to the one below before passing it to displaySmallCapsString
:
function stringToSmallCaps(input: string): SmallCapsString {
return input.toLowerCase() as SmallCapsString
}