type UserName = typeof UserName interface User { name: StringOf<UserName> age: number } function validateName(s: string): StringOf<UserName> { // validation logic here return { value: s } } #wejs
User { id: StringOf<UserId> name: StringOf<UserName> age: number } function validateId(s: string): StringOf<UserId> { // another validation logic for UserId return { value: s } } #wejs
} type UserName = string & { readonly _UserNameBrand: unique symbol } function validateId(s: string): UserId { // validation logic for UserId return s as UserId } function validateName(s: string): UserName { // validation logic for UserName return s as UserName } #wejs