The Best Ways to Organize and Define your TypeScript Types!

Поделиться
HTML-код
  • Опубликовано: 23 авг 2024
  • Where should you define your interfaces, enums, etc? Should they be global or should we import each type when needed? In this video, we go over a few best practices for where and when to define those TypeScript types using a simple Node.js Express application.
    GitHub Repo: github.com/cov...
    Express Template Repo: github.com/cov...
    Don't forget to like this video and subscribe to our channel - we're publishing more videos and walkthroughs every week. Comment below and let us know what you'd like to see next!
    Join the Covalence community: covalence.io
    Shop Covalence merch: covalence.merc...

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

  • @sathishkannan6600
    @sathishkannan6600 9 месяцев назад +4

    I would never use .d.ts files as typescript doesn't check these files by default. When we enable checking these files, typescript will scan even node_modules. Better to stick with types.ts files

    • @covalence-io
      @covalence-io  9 месяцев назад

      I've never had an issue with TypeScript not checking them by default. Do you have a tsconfig or no? Also if you're using types for npm packages, those .d.ts files will be in your node_modules @types folder anyway. If you do not want this behavior, I believe you can exclude folders like node_modules from being looked at.

  • @gamingbud926
    @gamingbud926 7 месяцев назад

    Spectacular! Thanks for the advice.

  • @sadlife7262
    @sadlife7262 Год назад +1

    Amazing tutorial! Thanks for sharing this knowledge, i always get a bit confused when thinking about how will i organize the types.

    • @covalence-io
      @covalence-io  Год назад

      100%! Glad you enjoyed and hope this helps make your projects a little bit easier moving forward :)

  • @TypescriptErrorsCentral-hg7hv
    @TypescriptErrorsCentral-hg7hv 3 месяца назад

    🚀 Tired of banging your head against the wall with TypeScript errors? Look no further than TypescriptErrorsCentral! 🎉 Dive deep into TypeScript & JavaScript errors (even those pesky frameworks!) with crystal-clear examples to squash bugs for good. Perfect for devs of any level! Plus, our community rocks-drop your error message in the comments and let's tackle it together. Don't miss out-subscribe now and kiss those headaches goodbye! 💻✨ #typescript #javascript #programming #errors #coding #devcommunity

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

    Great advice 👍 thanks.
    Can you explain when to use interface and type for reusability

    • @covalence-io
      @covalence-io  Год назад +1

      So types can be primitives whereas interfaces cannot, but for the most part, and in all other cases, interfaces should most likely be used over a type. Interfaces provide better type checking capabilities and allow for more thorough errors to be shown at build/compile time. There are a lot of people that feel that types should be used when you're talking about a physical model whereas interfaces should represent an abstract model that many different models can implement, but I tend to disagree with this just a bit. Personally, I tend to think that types should be used when you want a final declaration of a model that you do not want the possibility of extending further (interfaces can be redeclared multiple times and thus the model extended) whereas if you don't mind that aspect, I'd go with an interface.

  • @deep_kungch3010
    @deep_kungch3010 8 месяцев назад

    So helpful thank you😊

  • @amranmohamed377
    @amranmohamed377 10 месяцев назад

    Can not find namespace models

    • @covalence-io
      @covalence-io  10 месяцев назад

      It's created at the 2min mark

  • @cherrycasicas6828
    @cherrycasicas6828 3 месяца назад

    code gymnastic