5 Tips for Classier TypeScript

  Рет қаралды 4,970

Andrew Burgess

Andrew Burgess

Күн бұрын

Пікірлер: 25
@LuKaSSthEBosS
@LuKaSSthEBosS Жыл бұрын
Nice explanation for private fields! Been working with typescript classes for some time, and it's been really enjoyable! Great video
@whatplan4335
@whatplan4335 Жыл бұрын
Great video Classes are a really nice way to quickly define a type and constructor in one spot with not that much code
@gosnooky
@gosnooky Жыл бұрын
Interesting. I've used the 'this' argument to create sort of an active record to classes that are serializable and validatable with class-transformer and class-validator, so I can call something like User.from({ id: 1, name: 'Bob' }) to pass a POJO that was JSON into an instance of the class. I never really understood how it works, but it does.
@dimitro.cardellini
@dimitro.cardellini Жыл бұрын
Great video, thanks. Could you please record something about alternative approaches: factories and more exotic type classes?
@MindlessTurtle
@MindlessTurtle Жыл бұрын
Why do I get a bad feeling when using assertions and guards? Feels like building on shaky ground.
@doremicocoparis9410
@doremicocoparis9410 Жыл бұрын
Actually works well, you are just making explicit your invariants. Doesn't solve bad designs or bugs for you, but when they happens you locate them MUCH MORE quickly (which gives you an opportunity to iterate on your design)
@otek_
@otek_ Жыл бұрын
I know what you mean. The assertion predicate feels like it *could* be quite arbitrary and prone to going out of sync. For instance, if the type gets an additional field that would have to be included in your assertion's type predicate for it to remain valid, how would you know?
@doremicocoparis9410
@doremicocoparis9410 Жыл бұрын
For this you need to use an other pattern, the exhaust never pattern for example
@valikonen
@valikonen Жыл бұрын
Very nice list. Also soft private fields can be accessed with: component['my_db_pass']. In angular we use a lot this approach in tests. It will be great to make a video for adding an external npm package and his types.
@nefthy
@nefthy 2 ай бұрын
#2. private is not a security mechanism.
@PickleRiiiiiiick
@PickleRiiiiiiick Жыл бұрын
Love it. Thank Andrew.
@gantoreno
@gantoreno Жыл бұрын
Awesome video! Btw, what font are you using? Looks neat!
@andrew-burgess
@andrew-burgess Жыл бұрын
Thanks! It's Mono Lisa!
@Noam-Bahar
@Noam-Bahar Жыл бұрын
@@andrew-burgess that's the best name for a font I've heard so far
@reverser41
@reverser41 Жыл бұрын
regarding your last tip, is there any way to make every instance method of a class to be called with instance, how can i make it throw or make invalid when getFullname() is called
@hansschenker
@hansschenker Жыл бұрын
In Typescript every value is also a type. The type fortyTow = 42 has the value 42, {} is of type object , ...
@jenspalmqvist
@jenspalmqvist Жыл бұрын
But if you do 'let something: {}' you can assign everything except null and undefined to that variable, so be careful using that if you want the thing to be an actual object.
@andrew-burgess
@andrew-burgess Жыл бұрын
Good reminder!
@0tickpulse173
@0tickpulse173 Жыл бұрын
Your vim reminds me of nvchad
@andrew-burgess
@andrew-burgess Жыл бұрын
Ha! I tried nvchad for a few days just recently, but switched to kickstarter.nvim. No magic, just a good base config.
@0tickpulse173
@0tickpulse173 Жыл бұрын
@@andrew-burgess lol, im setting up kickstarter.nvim too currently
@kashmirtechtv2948
@kashmirtechtv2948 20 күн бұрын
Aren't we making the things harder unnecessarily?
@artemkotelevych2523
@artemkotelevych2523 Жыл бұрын
js is a joke
@thedelanyo
@thedelanyo Жыл бұрын
p.getFullName.bind(p) ,,, I'll rather try avoiding `this` whenever possible 😂😂😂
@Luxcium
@Luxcium Жыл бұрын
Yea Classes are _way better than all that hype about Functional programming…_ I love using classes to create my *Functors,* extend them into *Monad,* but it is cool also with a *Nothing* to create some *Maybe* and then also creating some *Left* and *Right* and *Either* the usual stuff… _Andrew_ 🦸🏻‍♂️ has a pretty interesting video about an *Optional* you must absolutely look into it, the homework 📚 to the reader is to use a class to implement the Option type of his other video 😅😅😅😅
Interfaces vs Type Aliases: what's the difference?
10:20
Andrew Burgess
Рет қаралды 22 М.
any vs unknown vs never: TypeScript demystified
8:01
Andrew Burgess
Рет қаралды 24 М.
Farmer narrowly escapes tiger attack
00:20
CTV News
Рет қаралды 12 МЛН
Players vs Pitch 🤯
00:26
LE FOOT EN VIDÉO
Рет қаралды 138 МЛН
Муж внезапно вернулся домой @Oscar_elteacher
00:43
История одного вокалиста
Рет қаралды 7 МЛН
Generics: The most intimidating TypeScript feature
18:19
Matt Pocock
Рет қаралды 184 М.
old TypeScript syntax I just discovered
8:54
Andrew Burgess
Рет қаралды 4,1 М.
JavaScript Prototypes: The interview question that stumped me
17:16
techgirlinstyle
Рет қаралды 1,4 М.
Object Oriented vs Functional Programming with TypeScript
12:07
5 Tips for Writing BETTER For Loops in JavaScript
16:15
James Q Quick
Рет қаралды 70 М.
Function Overloading in TypeScript (I was wrong)
10:24
Andrew Burgess
Рет қаралды 14 М.
My Favorite TypeScript Tips and Tricks
10:21
Lachlan Miller
Рет қаралды 7 М.
will i never understand this? unknown.
12:05
Andrew Burgess
Рет қаралды 3,9 М.
How Did I Not Know This TypeScript Trick Earlier??!
9:11
Josh tried coding
Рет қаралды 217 М.
Farmer narrowly escapes tiger attack
00:20
CTV News
Рет қаралды 12 МЛН