Skip to content

Latest commit

 

History

History
77 lines (70 loc) · 2.93 KB

refined-type.md

File metadata and controls

77 lines (70 loc) · 2.93 KB

Refined Type / Type Refinement

A refined type is simply a subset of a larger type.

Type refinement is the process of converting a large type to a refined type. We use smart constructors to do type refinement.

For example:

  • all UUIDs are valid strings, but not all strings are valid UUIDs
  • UUIDs are a refined type of string
  • the function makeUuid(input: string): Uuid:
    • takes a string
    • makes sure it contains a valid UUID
    • spits out a UUID built from that string

In a business application, many (if not most) of the safe types will actually be refined types.

  • Most input data from APIs or web browsers will be converted from strings to the types that form the business domain.
  • Same goes for all of the data retrieved from the business's databases.