on-internet
← Community

How to do isomorphic types in TypeScript

Stack Overflow ·

I have a file file.ts: let a: Message = "foo" let b: Message = "bar" let c: Message = "baz" Now I have a second file file2.ts type Message = string function fun(abc: Message): void { } Now function fun will allow me to pass stringto it, instead of Message, because it is only a type alias. Is there some way to isomorphic types, that is, a type that is just like another type, but there will be a strict check. So basically like Haskells newtype.

Comments

Sign in or sign up to comment and upvote.

No comments yet.