TypeScript Transformations with Pick and Omit

Поделиться
HTML-код
  • Опубликовано: 9 апр 2023
  • These two TS built-in utilities make it really easy to transform your types to build complex systems with the right amount of interconnectedness.
    My Links
    shaky.sh
    shaky.sh/tools
  • НаукаНаука

Комментарии • 7

  • @wlockuz4467
    @wlockuz4467 Год назад +3

    Pick and Omit fit really with REST API calls because when creating resources, say a User you don't have an id but when getting a user from backend you do.
    So you can have one universal User type and you can Omit the id when creating a user but use the type as is when retrieving it.
    Use something like type-fest on top of it which has some nice utility types such as SetOptional and SetRequired and you have a really good basic way to interface with a REST API.

  • @mohamedatta7866
    @mohamedatta7866 5 месяцев назад

    Thanks man 🙏

  • @Luxcium
    @Luxcium Год назад

    I love the scene 🎬 composition with the perfect balance in colour and the blue farther away on the left (the opposite side of when you shall point to indicate the inclusion of a card) the mnemonics is 💭 I *Left* a card for you in the corner 😅😅😅😅 also remember that it is up above ☝🏼 but it seems like it is the easy part 😊

  • @cg219
    @cg219 Год назад

    Nice tip, I didn't know about this. Thanks!

  • @adamszalkowski8226
    @adamszalkowski8226 Год назад

    Thank you for the tip! Idea for a follow-up: Why do I need OmitStrict in the presence of discriminated unions and how do I actually filter the props to exclude the unnecessary ones.

  • @shemmuthanga6352
    @shemmuthanga6352 Год назад

    Another difference between the two is that Pick is 'strict' while Omit is not.

  • @JDalmasca
    @JDalmasca Год назад

    Pick is a lot more useful when picking complex/ nested types. Picking primitive typed properties does not seem like something you'd usually use unless your goal is coupling it to the base type, hoping to detect/ prevent future base type changes from breaking your app. Your documentation/ intent comment hits on this idea.