In this lecture, we're going to discuss an experimental feature called Decorators.
Every feature of TypeScript we've explored so far has been related to type safety.
TypeScript does an extremely good job of helping us verify the types of our data.
Type safety is the main selling point of TypeScript.
There's another side of TypeScript we haven't had a chance to explore.
It allows us to write next generation JavaScript.
JavaScript is constantly evolving.
There's an official committee responsible for deciding what features get added to the language.
This committee is called T c 39.
Their discussions are open to the public.
We're able to view what they're working on.
Typically, features go through a process.
The first stage in the process is called straw person during this part of the process.
Members of the committee may propose a new idea.
If members like the idea, they'll move on to the next stage next.
One of the members will begin drafting a document of the proposal.
This document will include an extensive description of how the feature will work in the JavaScript language.
At this point, members will discuss if there are problems with this proposal.
The draft will be revised dozens of times throughout this process in the next stage.
Members will begin writing the syntax rules for the feature.
The team works with another team called Babel to make this feature a reality.
Beeple is a library for writing next generation JavaScript in our applications.
Developers can test new features before they become available in browsers.
After feedback has been implemented, the next stage is where members discuss any last issues with the
proposal.
If there aren't, the feature is moved on to the last stage, which is to make the feature an official
part of the language.
In the resource section of this lecture, I provide a link to the official list of T. S. Thirty nine
proposals, as you can see, the list is almost endless.
The feature we're interested in is called decorators.
As of this video, you should be able to find it under stage two.
Decorators are an upcoming feature in JavaScript.
It's a feature heavily used in Angular.
If we want to learn angular learning decorators is a must.
We have two options for working with decorators.
We can use Babel, which will require additional setup.
Luckily, TypeScript supports decorators.
One of the extra benefits of using TypeScript is being able to access newer features in JavaScript.
So what are decorators?
Why does angular use them?
Decorators are functions for extending business logic or adding metadata.
Sounds cool, but doesn't really explain what decorators are.
Let me give you an analogy.
Let's imagine we had a Christmas tree by themselves.
Christmas trees are plain and boring.
That's why we add decorations to them.
Decorations can liven up a tree.
It doesn't matter how many decorations you've added to the tree, it's still considered a tree in a
similar sense.
Decorators work the same way they allow us to modify an existing piece of code after the decorator has
made its modifications were returned the same piece of code, but with the modifications.
Let's look at an example of what problems decorators solve.
We have two classes with the same property.
Imagine if we had two classes with dozens of similar properties and methods, we should avoid repeating
the same code whenever possible.
This problem is as old as time.
Avoiding duplicate code is an issue developers face throughout the years.
Developers have come up with solutions for fixing this issue.
We can use high order components, composable functions and closures.
You may be familiar with these solutions if you worked with React or view each of these solutions works,
but there are some drawbacks to each of them.
Decorators resolve a lot of the issues with these other patterns.
One of the advantages of decorators is that we can apply them to classes, properties, methods, accessories
and parameters.
Thus, they can reach certain areas in our code where other patterns can't.
All right, enough talk.
Let's start writing some code.
We'll get started in the following lecture.