Casting — or more properly, type assertion — is not conversion/coercion. It has no runtime effect in TypeScript.¹ It's just the process of telling TypeScript that a variable or property is of the type you're casting it to asserting. In your first example, a
gets the exact same value that myType
has in it, it's just that the TypeScript compiler then believes a
contains a boolean. That type information disappears before the code is run, since TypeScript is compiled to JavaScript without decorating the code to convey type information, and JavaScript variables are loosely typed.
To actually convert the value, you'd use conversion (such as your Boolean(myType)
example) instead.
¹ Don't over-generalize this to other languages, such as Java or C#. This is one of the reasons TypeScript calls the process type assertion rather than casting. Casting may or may not be conversion in those other languages depending on the cast; and separately casting in those other languages can have an effect on runtime behavior.