Skip to content

Commit b8a4ebc

Browse files
committed
New: added glossary entry Flavoured Type
1 parent 2e5484a commit b8a4ebc

File tree

4 files changed

+80
-0
lines changed

4 files changed

+80
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ The following changes have been completed, and will be included in the next tagg
7777
- added End-User
7878
- added Entity
7979
- added Exported Item
80+
- added Flavoured Type
8081
- added Value Object
8182

8283
### Fixes

TEMPLATE.md

+1
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,6 @@ Table of Contents:
3737
[End-User]: ../../glossary/end-user.md
3838
[Entity]: ../../glossary/entity.md
3939
[Exported Item]: ../../glossary/exported-item.md
40+
[Flavoured Type]: ../../glossary/flavoured-type.md
4041
[Value Object]: ../../glossary/value-object.md
4142

glossary/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Table of Contents:
2323
- [End-User][End-User]
2424
- [Entity][Entity]
2525
- [Exported Item][Exported Item]
26+
- [Flavoured Type][Flavoured Type]
2627

2728
[ADOPTION]: ../impacted-areas/ADOPTION.md
2829
[CONTRIBUTIONS]: ../impacted-areas/CONTRIBUTIONS.md

glossary/flavoured-type.md

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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

Comments
 (0)