-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Cover union types, type aliases, type guards #74
Conversation
@@ -0,0 +1,197 @@ | |||
# Introduction | |||
|
|||
TODO |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me write one for you if that's okay:
When thinking about types, sometimes it is useful to think about operations on those types -- if we have something which is both a
Fridge
and aToaster
, how can we best describe this amalgamation?
Well, usually in the same way we just did -- as aFridge & Toaster
.
This kind of basic type arithmetic can be incredibly useful in being more expressive with your types, helping you say what you mean without jumping through classical inheritance-based hoops.
In TypeScript, we support three main productions which operate on types - [Unions](# Union Types), [Intersections](# Intersection Types), and [Aliases](# Type Aliases).
Supporting these we have [Type Guards](# Type Guards), boolean-returning functions meant to indicate to the typesystem weather an argument is to be considered of a narrowed type in a given branch of code.
Using these constructs correctly can enhance the semantic meaning of your types and help create a strongly typed, meaningful interface for your TypeScript program.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's pretty great, though, I'm not 100% certain we're going to have intersection types here; it would be appropriate though.
Cover union types, type aliases, type guards
@sandersn and @weswigham if you have feedback about recent changes, I'd be open to still making amendments. |
I still don't like "It just so happens Typescript has type guards". 😣 |
Fixes #37 and partially addresses #35