|
| 1 | +# Flavoured Type |
| 2 | + |
| 3 | +A _flavoured type_ is a variation on [branded types][Branded Type]. |
| 4 | + |
| 5 | +```typescript |
| 6 | +type WeakUuid = string & { |
| 7 | + _type?: "@safelytyped/uuid"; |
| 8 | +} |
| 9 | + |
| 10 | +type WeakCombUid = string & { |
| 11 | + _type?: "@safelytyped/combuid"; |
| 12 | +} |
| 13 | +``` |
| 14 | +
|
| 15 | +The difference between _branded types_ and _flavoured types_ is that _flavoured types_ make the `_type` property **optional**. |
| 16 | +
|
| 17 | +Why do we do that? Isn't it much less [robust][ROBUSTNESS]? |
| 18 | +
|
| 19 | +They were invented to help with unmarshalling data from a database or equivalent. See [this blog post](https://spin.atomicobject.com/2018/01/15/typescript-flexible-nominal-typing/) for more details. |
| 20 | +
|
| 21 | +[ADOPTION]: ../impacted-areas/ADOPTION.md |
| 22 | +[CONTRIBUTIONS]: ../impacted-areas/CONTRIBUTIONS.md |
| 23 | +[CORRECTNESS]: ../impacted-areas/CORRECTNESS.md |
| 24 | +[GOVERNANCE]: ../impacted-areas/GOVERNANCE.md |
| 25 | +[PROJECT-MAINTENANCE]: ../impacted-areas/PROJECT-MAINTENANCE.md |
| 26 | +[ROBUSTNESS]: ../impacted-areas/ROBUSTNESS.md |
| 27 | +[SECURITY]: ../impacted-areas/SECURITY.md |
| 28 | +[TESTABILITY]: ../impacted-areas/TESTABILITY.md |
| 29 | +[Base Class]: ./base-class.md |
| 30 | +[Branded Type]: ./branded-type.md |
| 31 | +[Caller]: ./caller.md |
| 32 | +[CQRS]: ./CQRS.md |
| 33 | +[Data Bag]: ./data-bag.md |
| 34 | +[Data Guard]: ./data-guard.md |
| 35 | +[Data Guarantee]: ./data-guarantee.md |
| 36 | +[Default Value]: ./default-value.md |
| 37 | +[Defensive Programming]: ./defensive-programming.md |
| 38 | +[Dependency]: ./dependency.md |
| 39 | +[Dependency Injection]: ./dependency-injection.md |
| 40 | +[Docblock]: ./docblock.md |
| 41 | +[End-User]: ./end-user.md |
| 42 | +[Entity]: ./entity.md |
| 43 | +[Exported Item]: ./exported-item.md |
| 44 | +[Flavoured Type]: ./flavoured-type.md |
| 45 | +[Function Prefix]: ./function-prefix.md |
| 46 | +[Function Signature]: ./function-signature.md |
| 47 | +[Hard-Coded]: ./hard-coded.md |
| 48 | +[Identity]: ./identity.md |
| 49 | +[Immutability]: ./immutability.md |
| 50 | +[Inherited Method]: ./inherited-method.md |
| 51 | +[Instantiable Type]: ./instantiable-type.md |
| 52 | +[Mandatory Dependency]: ./mandatory-dependency.md |
| 53 | +[Nominal Typing]: ./nominal-typing.md |
| 54 | +[Optional Input]: ./optional-input.md |
| 55 | +[Overridden Method]: ./overridden-method.md |
| 56 | +[Plain Object]: ./plain-object.md |
| 57 | +[Primitive Type]: ./primitive-type.md |
| 58 | +[Protocol]: ./protocol.md |
| 59 | +[Refined Type]: ./refined-type.md |
| 60 | +[Rest Parameter]: ./rest-parameter.md |
| 61 | +[Reusability]: ./reusability.md |
| 62 | +[Side Effects]: ./side-effects.md |
| 63 | +[Smart Constructor]: ./smart-constructor.md |
| 64 | +[Structural Typing]: ./structural-typing.md |
| 65 | +[Type Alias]: ./type-alias.md |
| 66 | +[Type Casting]: ./type-casting.md |
| 67 | +[Type Guarantee]: ./type-guarantee.md |
| 68 | +[Type Guard]: ./type-guard.md |
| 69 | +[Type Inference]: ./type-inference.md |
| 70 | +[Type Predicate]: ./type-predicate.md |
| 71 | +[Type Signature]: ./type-signature.md |
| 72 | +[User-Supplied Functional Options]: ./user-supplied-functional-options.md |
| 73 | +[User-Supplied Input]: ./user-supplied-input.md |
| 74 | +[User-Supplied Options]: ./user-supplied-options.md |
| 75 | +[User-Supplied Optional Dependencies]: ./user-supplied-optional-dependencies.md |
| 76 | +[Value]: ./value.md |
| 77 | +[Value Object]: ./value-object.md |
0 commit comments