5 Tips for Classier TypeScript

Поділитися
Вставка

КОМЕНТАРІ • 24

  • @MindlessTurtle
    @MindlessTurtle Рік тому +5

    Why do I get a bad feeling when using assertions and guards? Feels like building on shaky ground.

    • @doremicocoparis9410
      @doremicocoparis9410 Рік тому +1

      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_ Рік тому +1

      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

  • @dimitro.cardellini
    @dimitro.cardellini Рік тому +2

    Great video, thanks.
    Could you please record something about alternative approaches: factories and more exotic type classes?

  • @gosnooky
    @gosnooky Рік тому +2

    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.

  • @whatplan4335
    @whatplan4335 Рік тому +2

    Great video
    Classes are a really nice way to quickly define a type and constructor in one spot with not that much code

  • @artemkotelevych2523
    @artemkotelevych2523 Рік тому +1

    js is a joke

  • @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

  • @LuKaSSthEBosS
    @LuKaSSthEBosS Рік тому +1

    Nice explanation for private fields! Been working with typescript classes for some time, and it's been really enjoyable! Great video

  • @nefthy
    @nefthy 19 днів тому

    #2. private is not a security mechanism.

  • @0tickpulse173
    @0tickpulse173 Рік тому +1

    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 Рік тому +1

      @@andrew-burgess lol, im setting up kickstarter.nvim too currently

  • @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.

  • @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

  • @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!

  • @PickleRiiiiiiick
    @PickleRiiiiiiick Рік тому

    Love it. Thank Andrew.

  • @thedelanyo
    @thedelanyo Рік тому

    p.getFullName.bind(p) ,,, I'll rather try avoiding `this` whenever possible 😂😂😂

  • @Luxcium
    @Luxcium Рік тому +1

    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 😅😅😅😅