|
|
|
|
|
by smichel17
2161 days ago
|
|
Is there any language that does both? I've really enjoyed js/ts's structural typing for prototyping, but there are certain places I miss nominal typing, particularly with input validation (and other "primitive type, plus restrictions") scenarios. For example, an integer that's used to index into an array, so it must be positive. Or a string that's a valid street address. You can maintain that info by packing it into a unique structure (ie, wrap in an object, using a unique key), but that's awkward to access. Or you can always pass around the parent object (eg, House), which has a unique structure, but then you're introducing unnecessarily tight coupling which is a disaster to maintain. |
|
- https://github.com/gcanti/newtype-ts
- https://github.com/Microsoft/TypeScript/issues/4895#issuecom...
but it isn't as nice as say Python's `typing.NewType` or Haskell's `newtype`