While reviewing type assertions, I noticed something interesting about the last three variable assignments - they don't produce errors. It's perplexing because I thought I was trying to change 'helo' into 'hello', which should result in errors.
The compiler seems to be functioning correctly in my text editor, as indicated at the bottom. Errors are only caught when interacting with the variables, and not during assignment, which is surprising.
Flexibility in rules or validations may allow for different scenarios to work, leading to this outcome. However, in this instance, I believe I'm creating an incompatibility right at the time of assignment.
(The results remain unchanged with type Helo = 'helo'
.)
type Helo = string
type Hello = 'hello'
let helo: Helo = 'helo'
// These 3 lines don't generate any errors
let hello = helo as Hello
let h = <Hello>'helo'
let hl = <'hello'>'helo'
const greet = (msg: Hello) => console.log(msg)
>>greet(helo) // tsserver: 2345: Argument of type 'string' is not assignable to parameter of type '"hello"'