6 ms·
In TypeScript you can enable this by using BrandedTypes like this: type UserId = string & { readonly __tag: unique symbol }; In Python you can use `NewType`
by presz 1y ago
In TypeScript you can enable this by using BrandedTypes like this:
type UserId = string & { readonly __tag: unique symbol };
In Python you can use `NewType` from the typing module:
from typing import NewType
from uuid import UUID
UserId = NewType("UserId", UUID)
- movpasd 1y agoIn Python 3.12 syntax, you can use type UserIs = UUID
- 12_throw_away 1y ago`type UserId = UUID` creates a TypeAlias, not the same thing (from a type checker's point of view) as a NewType [1]. [1] https://typing.python.org/en/latest/spec/aliases.html https://typing.python.org/en/latest/spec/aliases.html