If I Started Learning TypeScript, I'd Do This

แชร์
ฝัง
  • เผยแพร่เมื่อ 3 พ.ย. 2024

ความคิดเห็น • 67

  • @mattpocockuk
    @mattpocockuk ปีที่แล้ว +54

    Thanks for the ts-reset shoutout! Much appreciated.

    • @joshtriedcoding
      @joshtriedcoding  ปีที่แล้ว +4

      Such a simple and useful concept. Appreciate ya dude

    • @dvirberlo
      @dvirberlo ปีที่แล้ว

      A better way to add the types globally is to add then in tsconfig.
      The d ts files have different specific usage, as you mentioned in one of your recent videos.

    • @mattpocockuk
      @mattpocockuk ปีที่แล้ว +2

      ​@@dvirberlo Unfortunately not - tsconfig doesn't offer a truly ergonomic way to add types to the project. If you add it to "types" it becomes the ONLY types in your project. If you add it to typeRoots it breaks all sorts of other things.

    • @dvirberlo
      @dvirberlo ปีที่แล้ว +1

      Hmm. Thanks for correcting me. So this is the best hack, I suppose.

  • @filipniklas
    @filipniklas ปีที่แล้ว +34

    Missed opportunity to say "You don't want any 'anys' in your code" 😅 otherwise, good stuff! 👍

  • @AliCaliskan-km5jc
    @AliCaliskan-km5jc ปีที่แล้ว +1

    Always happy when I see a new video upload by you

  • @nirjoyhasanantor3149
    @nirjoyhasanantor3149 ปีที่แล้ว +7

    I am exited to learn something new in typescript I recently shifted from JavaScript to typescript and using typescript for new projects it is really nice

    • @joshtriedcoding
      @joshtriedcoding  ปีที่แล้ว +1

      Glad it's going well for you using it! Learning TS definitely takes some getting used to, but once you kinda get it you don't wanna go back

    • @nirjoyhasanantor3149
      @nirjoyhasanantor3149 ปีที่แล้ว +1

      @@joshtriedcoding yeah I am loving it

  • @damagee8141
    @damagee8141 ปีที่แล้ว +5

    I have been using "noUncheckedIndexedAccess" for some months. And there are good reasons to use it but there is a trade-off.
    When you are using a basic for-loop that iterates over the elements of an array, you will have to check if element[i] is undefined or not because typescript doesn't know. A better way would be to use a bang right after it, ( like this: arr[i]! ) to tell typescript that you know that this elements won't be undefined but to me it feels really bad to do this and checking for undefined with an if-clause is even worse. The best way to work around this is to use for-of-loops but sometimes it's just more convenient to use a regular for-loop (e.g. you don't want to start with the first element, you want to access the array in a different order, ...)
    People always talk about how great typescript's inference is and for the most part this is true but for things like this it limits you more than it helps.
    I still recommend using "noUncheckedIndexedAccess", just know that it's not perfect.

  • @XxGgunJIZZxX
    @XxGgunJIZZxX ปีที่แล้ว +4

    I love all of your points here. I do feel that I need to specify an edge-case where I feel "any" is allowed 😅 My project is currently using a library that contains a LOT of components, and it has not been converted to typescript yet. It would be absolute hell to create and maintain all the prop definitions for all those components. In such a case, I definitely feel "any" is allowed

  • @kwtestwnch
    @kwtestwnch ปีที่แล้ว +3

    Love your vids and how you explain the issue and solutions!

  • @omarshref4803
    @omarshref4803 ปีที่แล้ว +1

    continue the good work man love you and your videos ❤❤❤

  • @greeffer
    @greeffer ปีที่แล้ว +1

    Wow! The best part: "You don't want any anys in your code."

  • @snk-js
    @snk-js ปีที่แล้ว +1

    an excellent communicator, gratz

  • @PostMeridianLyf
    @PostMeridianLyf ปีที่แล้ว +1

    Im thankful for you pointing out these issues but reluctant to add another library. Rather crate my own solution.

  • @8koi245
    @8koi245 ปีที่แล้ว +1

    Ohhh yeah I'd love a code review! I wish I had time to finish my last project tho

  • @Endrit719
    @Endrit719 ปีที่แล้ว

    Josh tried coding and he fckin rocked it

  • @alexanderkomanov4151
    @alexanderkomanov4151 ปีที่แล้ว

    Wow! It is was amazing!

  • @Luxcium
    @Luxcium ปีที่แล้ว +16

    This guy is smart and he is saying the truth and he is explaining it clearly and I love this channel ❤Josh is one of the best tutors I’ve ever seen and I think he is going to be a big deal soon the guy is going to be more than a million followers soon !!! 🎉🎉🎉🎉

    • @invinciblemode
      @invinciblemode ปีที่แล้ว +2

      But you’re learning from someone with little to no work experience?

    • @invinciblemode
      @invinciblemode ปีที่แล้ว +1

      @@saufth lmao sure buddy

    • @joshtriedcoding
      @joshtriedcoding  ปีที่แล้ว +1

      Appreciate you man. It really means a lot.

    • @Luxcium
      @Luxcium ปีที่แล้ว +3

      @@invinciblemode People who have a ton of working experience don’t have the time or the will of experimenting with TypeScript and some people who have work experience learned React before even Learning JavaScript… This dude (Josh the amazing) is spending all day and night reading and learning about TypeScript and he is giving the important stuff one should know about… So maybe he is not working in a team where everything is being decided for you, or worse where everyone follows no conventions and are producing inconsistent code but Josh is working on this day and night for at least one year so I don’t understand what your argument is all about…

    • @invinciblemode
      @invinciblemode ปีที่แล้ว +2

      @@Luxcium my argument is that he hasn’t seen a real codebase

  • @andreyokhrimenko2271
    @andreyokhrimenko2271 ปีที่แล้ว

    Thanks for video, can some one explain in which sutuation we do fetch and dont know what we get? Real world example? I learn web-dev by free courses and had no examples of this sitiation.

  • @_aryan_570
    @_aryan_570 ปีที่แล้ว +1

    I never used TypeScript, but will it make my life easier as a developer? Should I learn it?

    • @joshtriedcoding
      @joshtriedcoding  ปีที่แล้ว +5

      oh yeah. I'd never to back. Definitely

  • @vikashkhati007
    @vikashkhati007 ปีที่แล้ว +1

    Can you please make a video on your vs code setup which theme are you using which extension are you using , like you are getting code complete sugesstion.

  • @YOUdudex
    @YOUdudex ปีที่แล้ว

    Cool video, thanks Josh

  • @eugeneponomarov7429
    @eugeneponomarov7429 ปีที่แล้ว

    `noUncheckedIndexedAccess` is not something I recommend to use, you will be forced to check every time you access an array. It's better to leave it as it is and just type cast to possible undefined when you now it's going to happen.

  • @vim55k
    @vim55k ปีที่แล้ว

    Is there any codebase that uses nouncheckedindexaccess??
    I am all for it, but it requires to do many checks

  • @anonanon7368
    @anonanon7368 ปีที่แล้ว

    I like typescript-eslint implementation from create t3 app, it prevents all these problems

  • @carlosricardoziegler2650
    @carlosricardoziegler2650 ปีที่แล้ว

    Great video!!

  • @QwDragon
    @QwDragon ปีที่แล้ว

    In most cases you should trust that your own apoi follows the schema and don't want to validate unknown. Using any with casting to expected type seems much more logical for me.

  • @TheIpicon
    @TheIpicon ปีที่แล้ว

    I've searched for noUncheked for so long!

  • @gradientO
    @gradientO ปีที่แล้ว

    5:25 How'd you share api type logic between client and api? (Like a typical nodejs and react app) Similar question for form validation

  • @8koi245
    @8koi245 ปีที่แล้ว

    hell yeah!

  • @daromacs
    @daromacs ปีที่แล้ว +1

    Josh, I have been into more advance TS because I'm into more advanced projects. Suddenly it came to my mind, what would be the differences of managing data with context api or custom hooks?, let's say fetching data, but also other kind of data such as states. Sometimes I am not sure when to use one or another, if possible could you make a video please? thanks!

    • @bloodylupin
      @bloodylupin ปีที่แล้ว

      if you get the state from a hook it won't be the same for every component. To have a single state you have to pass the state in the props and to avoid props drilling you need the context

  • @savit3r
    @savit3r ปีที่แล้ว

    Can you talk about why you use Yarn over NPM?

  • @czancdy144
    @czancdy144 ปีที่แล้ว

    hey josh i really enjoy your videos i have a request
    can u make a video on state management in nextjs app router with rtk query and how to use hooks provided by rtk query with ssr

  • @psyferinc.3573
    @psyferinc.3573 ปีที่แล้ว

    will yo udo a review with nextjs and supabase ?

  • @good-dev-student
    @good-dev-student ปีที่แล้ว

    This will be good with SvelteKit thank you Josh

  • @shayanCodingMaster
    @shayanCodingMaster ปีที่แล้ว

    Hi sir how can we train own ai model to generate new content like images, text, audio, video also add web searching functionality in Node js

    • @joshtriedcoding
      @joshtriedcoding  ปีที่แล้ว +1

      For text I trained some custom OpenAI models and that works super well if you kinda know what you're doing and how to make proper datasets (goes for any ML). For images I'd recommend using Replicate, WebDevCody has recently done a great video on this

    • @shayanCodingMaster
      @shayanCodingMaster ปีที่แล้ว

      @@joshtriedcoding thanks sir but I don't want to go openai side

    • @shayanCodingMaster
      @shayanCodingMaster ปีที่แล้ว

      @@joshtriedcoding I want to train my own ai models using tensorflow

    • @shayanCodingMaster
      @shayanCodingMaster ปีที่แล้ว

      @@joshtriedcoding I don't take money from my dad or any other friends or relatives, thus I can't pay any money. I favour complete freedom. If it is not free, I will do it for myself if I need to.

  • @NatnaelAbebe-og8bt
    @NatnaelAbebe-og8bt ปีที่แล้ว

    bro if I start learning web development to day is it worth or can I get a job please help me

  • @xoldyckk176
    @xoldyckk176 ปีที่แล้ว +2

    That string | undefined thing defeats the purpose of typescript. When you've annotated the type of a list as string[] it should be certain that everything inside that list will always be a string. This certainity is asserted by making sure whenever you're working with that list any kind of mutation to that list and its elements at runtime is done after explicit type checking. So, the place for explicit type checking should not be when utilizing the list or an element of that list. Therefore, it is more of a paradigm and mental model you need to have while working with typescript.

    • @joshtriedcoding
      @joshtriedcoding  ปีที่แล้ว

      Ah, interesting take man. This annotation just serves as an example of not having to deal with a never[]. This approach shines, specifically for react, when mapping over an array of items you're not certain to exist.

    • @Luxcium
      @Luxcium ปีที่แล้ว

      I dont think we must make the TypeScript conformant to our needs instead we must conform with TypeScript and when you know better than TypeScript you have the _as_ keyword to let the compiler know what you understand something it doesn’t… I do agree that it is annoying that TypeScript can not infer when it is trivial and obvious what an array contains but maybe it’s not the role of TypeScript after all… we must be mindful of the fact that it may be containing undefined or also based on your preferences you just need not to activate this level of strictness TypeScript gives you the choice!!! 😅

    • @gradientO
      @gradientO ปีที่แล้ว +1

      ​@@Luxciumlol this just makes me love Java's typing more

  • @schumanncombo
    @schumanncombo ปีที่แล้ว

    why do form validation with client side scripts at all ... inputs have a native way with min. max, required, pattern, range ... your code is 100% noob code too - and react for sissys. but anyway - there was some good hints for beginners for sure.

  • @patriciebakosova4878
    @patriciebakosova4878 ปีที่แล้ว

    Hey man! great video again, really helpful! How do I send you a DM? doesn't let me since I don't have you in my friends list.

    • @joshtriedcoding
      @joshtriedcoding  ปีที่แล้ว

      Weird, I'm pretty sure that should work. Have gotten a lot of DMs from people without being friends. Is there a specific error you're getting?

    • @patriciebakosova4878
      @patriciebakosova4878 ปีที่แล้ว

      @@joshtriedcoding all good now! it was actually my account that had it blocked..

  • @jayantrohila
    @jayantrohila ปีที่แล้ว

    create playlist of your video they are scatter scattered every where

  • @mohitcodeswell
    @mohitcodeswell ปีที่แล้ว

    Hey Josh 😂

  • @parlor3115
    @parlor3115 ปีที่แล้ว +1

    If I started learning TypeScript now, I'd stop and learn C#. It offers better type safety guarantees and the job are higher pay.