Consider the following scenario with two files, file.ts
:
let a: Message = "foo"
let b: Message = "bar"
let c: Message = "baz"
Now let's introduce a second file, file2.ts
type Message = string
function fun(abc: Message): void { }
When using function fun
, we can pass a string
instead of Message
due to it being a type alias. How can we create isomorphic types that behave like another type but enforce strict checks, similar to Haskell's newtype
?