I haven’t run into interfaces coincidentally matching in Go. Have you? It might happen more easily for primitive types, though, and Go does have a way to declare new types:
type UserId stringAre these simple aliases or nominally distinct types?
Re:TypeScript: Branded Types
by yencabulator on Thursday April 25, 2024 @11:06AM
(#40158453)
Nominally distinct.
I mean, they have to stay backwards compatible with Javascript. That kind of limits your options.
Not particularly - they could use distinct tokens (i.e. these brandings) on all types implicitly.
The other problem I've found with structural types in Typescript is that it can lead to some very complex type specifications. Instead of carefully thinking about and naming the entities in your system you can get some very hard to parse type spaghetti.
Determining types by what things appear to do instead of what they state they do seems like a generally unnecessary compromise in typing safety that isn't really worth the minuscule amount of effort it can save.