Skip to content

Instantly share code, notes, and snippets.

@dewey92
Last active October 6, 2018 17:16
Show Gist options
  • Select an option

  • Save dewey92/64ef12e208dd8af0993c42c1e0447fa7 to your computer and use it in GitHub Desktop.

Select an option

Save dewey92/64ef12e208dd8af0993c42c1e0447fa7 to your computer and use it in GitHub Desktop.
Branding example
declare function convertCtoF(degree: Celcius): Fahrenheit;
declare const fiveC: Celcius;
declare const fiveF: Fahrenheit;
convertCtoF(fiveF); // error :)
// Argument of type 'Brand<"Fahrenheit", number>' is not assignable to parameter of type 'Brand<"Celcius", number>'.
// Type 'Brand<"Fahrenheit", number>' is not assignable to type '{ _brand: "Celcius"; }'.
// Types of property '_brand' are incompatible.
// Type '"Fahrenheit"' is not assignable to type '"Celcius"'.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment