Fireship · @fireship

How to use TypeScript with React... But should you?

Uploaded April 19, 2021 · Length 6:36

How to use TypeScript with React... But should you?

Summary

Fireship discusses whether to use TypeScript with React, weighing pros and cons, and how to get started with TypeScript and React.

  • typescript with react
  • typescript pros and cons
  • typescript getting started
  • react development
  • javascript

Transcript preview

The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.

  1. 0:00

    when I started this YouTube channel four

  2. 0:01

    years ago most react developers would

  3. 0:03

    have laughed at the idea of using

  4. 0:04

    something like typescript you should

  5. 0:07

    you should nah bro like why would you

  6. 0:09

    take your beautiful functional

  7. 0:10

    JavaScript and bloat it with a bunch of

  8. 0:11

    type definitions that make it look like

  9. 0:13

    the real Jabba I was very skeptical of

  10. 0:15

    it myself when I first started using it

  11. 0:17

    in an angular project in 2017. now maybe

  12. 0:19

    it's just the Stockholm syndrome talking

  13. 0:21

    but after using it I've never wanted to

  14. 0:23

    go back but I don't think I'm alone

  15. 0:24

    because it was the second most loved

  16. 0:25

    technology on the 2020 stack Overflow

  17. 0:28

    survey in today's video you'll learn

  18. 0:29

    everything you need to know to get

  19. 0:30

    started with typescript and react but

  20. 0:32

    more importantly we'll talk about why or

  21. 0:34

    why not you should use it because

  22. 0:36

    there's a good case to be made for both

  23. 0:37

    sides of that argument if you're new

  24. 0:39

    here like And subscribe and become a pro

  25. 0:41

    member at fireship i o to get access to

  26. 0:43

    my full next JS react course to decide

  27. 0:45

    whether or not you want to use

  28. 0:46

    typescript let's take a look at two

  29. 0:48

    different projects side by side one with

  30. 0:50

    typescript and one without there are

  31. 0:51

    many different ways to add typescript to

  32. 0:53

    a react app in this case I'm using the

  33. 0:55

    create react app tool but specifying the

  34. 0:57

    typescript template the docs also have

  35. 0:59

    instructions for adding it to an

  36. 1:01

    existing project or you can learn how to

  37. 1:03

    set it up in next.js in my course if we

  38. 1:05

    look at the file system on these two

  39. 1:06

    projects side by side the most obvious

  40. 1:08

    difference is that the typescript

  41. 1:10

    project has files ending in dot TS or

  42. 1:12

    dot TSX but the weird thing is that if

  43. 1:15

    we look inside one of these files the

  44. 1:16

    code is exactly the same as the

  45. 1:18

    Javascript file and that actually brings

  46. 1:20

    up a good question what is typescript if

  47. 1:22

    my code is exactly the same typescript

  48. 1:24

    as a language is a superset of

  49. 1:25

    JavaScript that means vanilla JavaScript

  50. 1:27

    is also 100 valid typescript in other

  51. 1:30

    words it just adds extra optional

  52. 1:32

    features on top of regular JavaScript

  53. 1:34

    the relationship between scss and CSS is

  54. 1:37

    the same as typescript and JavaScript

  55. 1:39

    and that's really cool because it means

  56. 1:41

    you don't really have to learn anything

  57. 1:42

    to get started with it but here's the

  58. 1:44

    catch browsers don't know how to run

  59. 1:46

    typescript code what is this crap which

  60. 1:48

    means that we need a compiler to take

  61. 1:50

    our typescript code and transpile it or

  62. 1:53

    compile it down to regular JavaScript in

  63. 1:55

    our TS project you'll notice a special

  64. 1:57

    file called tsconfig its purpose is to