Another useful feature of TypeScript 2 is tagged union types which allows the possibility of simplifying your workflow when using interfaces and switch statements. It allows you to do type annotations in the interfaces, then use JavaScript in a function a
- [Instructor] Another useful feature of TypeScript 2…is tagged union types,…which allows the possibility of simplifying your workflow…when using interfaces and switch statements.…It allows to do type annotations in the interfaces,…then use plain old JavaScript in a function…and do very little type assertions.…This is particularly useful if…you want to do Redox with typeScript.…In our example we'll first define TypeScript interfaces…based off a recent course I've done around Framer…and then use JavaScript style to write a function…without using types.…
So the first thing we'll do,…we'll define three interfaces.…And as I mentioned, we'll define them around characters…that I've done in a previous course.…So the first one we'll define an Archer.…And the kind,…and again, this is purely hypothetical.…We're using this as an example.…We're not going run any particular code…in the browser this time,…but I just want to show you what it looks like.…So the kind is Archer.…
And if you're familiar with Redox,…this is going to look familiar…
Released
4/10/2017- Updating a local environment
- IDEs with TypeScript support
- Assigning null or undefined types
- Using control flow analysis
- Using tagged union types
- Using read-only properties
- Using mapped types
- Using objects spread and rest
- Leveraging external helper libraries
Share this video
Embed this video
Video: Tagged union types