Skip to content

Files

Latest commit

b8a4ebc · Jun 9, 2020

History

History
77 lines (70 loc) · 2.77 KB

flavoured-type.md

File metadata and controls

77 lines (70 loc) · 2.77 KB

Flavoured Type

A flavoured type is a variation on branded types.

type WeakUuid = string & {
    _type?: "@safelytyped/uuid";
}

type WeakCombUid = string & {
    _type?: "@safelytyped/combuid";
}

The difference between branded types and flavoured types is that flavoured types make the _type property optional.

Why do we do that? Isn't it much less robust?

They were invented to help with unmarshalling data from a database or equivalent. See this blog post for more details.