Skip to content

Commit

Permalink
docs: Explain branded types
Browse files Browse the repository at this point in the history
  • Loading branch information
l0b0 committed Feb 1, 2024
1 parent 25f890c commit 243ceeb
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/utils/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
/**
* Branded types can't be replaced with their underlying types. This means that we can't, for example, pass a `string`
* when a function expects a `PathString`. This clarifies the semantics of containers (variables, parameters) while
* allowing us to use the values of those containers as plain strings.
*
* See <https://egghead.io/blog/using-branded-types-in-typescript> for details.
*/

declare const __brand: unique symbol;
type Brand<B> = { [__brand]: B };

Expand Down

0 comments on commit 243ceeb

Please sign in to comment.