The Magic of TypeScript Decorators

The Magic of TypeScript Decorators

Fireship

5 лет назад

251,089 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Andrea Della Maggiora
Andrea Della Maggiora - 07.04.2023 15:58

Everything is very nice but the decorators seems more verbose implementation of a "pipe" function and, more general, function composition.
Very useful in OOP but seems like wanting to use a more "functional" paradigm, so why don't use it directly? I guess it could be easier and less verbose.

Ответить
Дмитро Онуфрієнко
Дмитро Онуфрієнко - 21.02.2023 18:12

what the song is playing?

Ответить
Kalahari
Kalahari - 11.01.2023 16:52

Top to bottom? Isn't it the other way around

Ответить
Bronx & Branx
Bronx & Branx - 01.01.2023 15:01

Nice. Thank you master

Ответить
DEA Agent Hank Schrader
DEA Agent Hank Schrader - 25.11.2022 18:07

Waiting for Lombok to create a typescript version of their library now.

Ответить
Kai Be
Kai Be - 14.11.2022 04:50

I don't understand. Angular JS requires Typescript. Google has the V8 engine. Why isn't Typescript natively supported yet?!

Ответить
kenzo
kenzo - 20.09.2022 18:37

what font are you using in vsc?

Ответить
1GobJroot
1GobJroot - 10.08.2022 14:27

why did his voice change midvideo

Ответить
Attila Varga
Attila Varga - 15.07.2022 23:03

This is just the basics.

Most of the decorators only add metadata and the class decorator will do the actual work while reading the metadata stored in the descriptors.

Ответить
Christopher Perisho
Christopher Perisho - 08.07.2022 22:34

How are TS decorators different from JS decorators?

Ответить
Saeed Uchiha
Saeed Uchiha - 23.06.2022 06:19

Not the best way to explain Decorators... But nice try

Ответить
ravel
ravel - 27.03.2022 15:36

Great video

Ответить
comod
comod - 12.12.2021 20:50

You lost me somewhere in the middle 😅. But seems to be something i should use

Ответить
Rolands Fridemanis
Rolands Fridemanis - 09.10.2021 01:20

That was the cleanest Typescript decorator explanation I've ever stumbled across. Keep up the good work!

Ответить
Javi
Javi - 10.09.2021 18:14

If javascript wouldn’t already be a mess, let’s sprinkle more on top

Ответить
Iago Campos
Iago Campos - 28.08.2021 02:34

Confusing

Ответить
Nohan Mohsin
Nohan Mohsin - 25.08.2021 20:48

the cgi is shit...I can tell you that much

Ответить
Quentin Mayo
Quentin Mayo - 24.08.2021 08:02

Is it just me or did his voice chance mid-way through the video?

Ответить
Morpheus
Morpheus - 18.08.2021 19:55

From c#, this is attributes.

Ответить
Vasyl Sumskyi
Vasyl Sumskyi - 06.08.2021 12:45

So easy, thanks!

Ответить
Jack Kirby
Jack Kirby - 30.07.2021 13:55

So they're like Java annotations but with less limitations?

Ответить
ammad khalid
ammad khalid - 08.07.2021 01:21

As python developer it makes sense so smooth. Thank you for great video!!!

Ответить
Bob Bass
Bob Bass - 16.06.2021 07:53

I like to think I'm pretty competent with typescript but this was way over my head. Possibly because I've never touched angular

Ответить
AIX
AIX - 02.05.2021 17:33

This dude walks cheerfully in the valley of death (inner js shit) 😵

Ответить
Ar Am
Ar Am - 28.04.2021 20:56

Ok, cool and dandy. But what has made ngrx go from Effect decorator to createEffect factory? Was it type safety or was it that decorators are still experimental? For some reason they did so. Not a good recommendation then for using decorators.

Ответить
Skyline
Skyline - 15.04.2021 09:43

Great tutorial overall but your misunderstanding about the property decorator caused me a lot of confusion. The "target" argument does not refer to the class but the prototype of the class (constructor function). And you didn't need to assign target[key] to the val variable as target[key] is undefined. You didn't need to assign any value at all to val as only the get and set functions refer to it using closures and the initial value is insignificant since you are assigning a value to it in the class itself.

And it's important to note that, when you do this, the property no longer stays a property of the actual instance object but rather becomes part of the prototype. To confirm, console.log(new IceCreamComponent()._proto__) and console.log(new IceCreamComponent()). You will notice that only the __proto_ object contains the flavor property but not the instance itself. And MORE IMPORTANTLY, different instances of the class will have access to the same flavor property. For example:

const Ice1 = new IceCreamComponent();
const ice2 = new IceCreamComponent();
ice1.flavor = 'chocolate';
console.log(ice1.flavor, ice2.flavor); // BOTH WILL RETURN CHOCOLATE FLAVOR!

I hope this helps everyone else who stumbles upon this and ends up as confused as me. :)

Ответить
Jim L.
Jim L. - 26.03.2021 15:47

Absolute gold!!! thank you!!

Ответить
D K
D K - 11.02.2021 21:58

I didn't quite understand how 'Object.freeze(SuperClass.constructor)' prevented the class from being extended? Inheritance would internally use 'SubClass.prototype = Object.create(SuperClass.prototype)'. Object.create would internally do 'return new SuperClass.prototype'.

Ответить
Mini Geek
Mini Geek - 02.01.2021 14:55

I literally have no closest idea what exactly is happening here... this video is for advanced folks only. I still think you need to change the way you explain with that monotonous tone.

Ответить
Ad Ici De
Ad Ici De - 25.12.2020 14:08

So if you don't do class-based ts/js, or almost not at all, you can use decorators where? Or actually, would there be a point at all to do this as opposed to composing functions functional style?

Ответить
himanshu shekhar
himanshu shekhar - 11.12.2020 21:05

Don't confuse, speed is set to Normal. Change the playback speed to 0.75. Thanks, Sir for this to the point explanation.

Ответить
Dr Poustevnik
Dr Poustevnik - 06.11.2020 21:56

Is there a way how to unpack the syntactic sugar of decorator?
In particular, I wonder how to re-write this:
```
@Emoji()
flavor = 'vanilla';
```
I would like to see how does the inner annonymous function inside `Emoji` acquires the `target` object.

Ответить
kurt estacion
kurt estacion - 23.10.2020 18:38

Hi Fireship. This content is great! btw, How long have you been coding if i may respectfully ask.

Ответить
Phu Nguyen
Phu Nguyen - 22.09.2020 07:28

Thanks, your explanation is far better than ts official doc :D

Ответить
Lucas N
Lucas N - 05.08.2020 05:06

how do you edit your video? how are you able to paste so much stuff without moving the cursor?

Ответить
Riddick 4Ever
Riddick 4Ever - 05.08.2020 03:42

lol could hav been started with simpler example...(for non angular people like me)

Ответить
Alsharif Eid
Alsharif Eid - 23.07.2020 19:42

I really appreciate the effort for trying to help people with your videos. But honestly you guys move to fast, and its annoying. its not even helpful.

Ответить
The Logic
The Logic - 29.04.2020 03:45

What about JavaScript Decorators ? learned from an online book (sort of) and now can' t even find a single video or resource related to it. WTH typeScript and python decorators videos are everywhere

Ответить
Sooryakiran Ponnath
Sooryakiran Ponnath - 26.04.2020 11:22

I cannot stress enough how much I love your videos. Sometimes I end up on your videos purely through a google search. I see Fireship and I instantly click.


You explain concepts in a concise yet understandable manner.

Ответить
Christian Heisch
Christian Heisch - 24.04.2020 13:19

Man, you seem to be explaining things for people who already know those things.
Way too fast, way too compressed.

Ответить
marcianoacuerda
marcianoacuerda - 23.04.2020 03:26

Wow didn’t know Angular left JS to turn into Spring 😂.

Ответить
Al Xx
Al Xx - 19.03.2020 03:32

Hurry Hurry !!

Ответить
UODZU-P
UODZU-P - 07.03.2020 21:09

This like anti ASMR with headphones, please consider using a noise gate. I can hear your lips smacking and swallowing the whole time. Its like nails on a chalkboard.

Ответить
Kristoffer Roen-Lie
Kristoffer Roen-Lie - 17.02.2020 12:00

Would love to see a bit more explanation on what and how decorators actually work instead of only code

Ответить