Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify and refine where possible #15

Merged
merged 6 commits into from May 27, 2022
Merged

Simplify and refine where possible #15

merged 6 commits into from May 27, 2022

Conversation

jossmac
Copy link
Member

@jossmac jossmac commented May 27, 2022

Opaques changes:

  • remove docs and exports for Transparent type generic (still used internally)
  • remove toTransparent util
  • rename toOpaque to castToOpaque
  • recommend unique symbols for stronger types

Misc. changes:

  • Only support boolean condition against assert()
  • Fix weird edge case with isDefined()
  • Docs tidy
Assert changes Opaque changes
assert changes image

- remove docs and exports for `Transparent` type generic
- remove `toTransparent` util
- rename ~toOpaque~ --> `castToOpaque`
- recommend unique symbols for stronger types
@@ -35,35 +35,33 @@ type ThingThree = Opaque<string, 'ThingTwo'>;
// 🚨 Non-unique `Token` parameter
```

You can, and should, use recursive types for your opaque types to make them stronger and hopefully easier to type.
While string literals are accepted tokens, we recommend [unique symbols](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-7.html#unique-symbol) for your opaque types to make them stronger. Each reference to a unique symbol implies a completely unique identity that’s tied to a given declaration.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recommendation on unique symbol use with opaque types

@jossmac jossmac requested a review from emmatown May 27, 2022 05:51
@jossmac jossmac merged commit fb21493 into main May 27, 2022
@jossmac jossmac deleted the reduce-and-simplify branch May 27, 2022 06:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants