DEV Community

Cover image for Start using TypeScript in React Projects
Shamaz saeed
Shamaz saeed

Posted on

4 2

Start using TypeScript in React Projects

What is TypeScript?

  • Superset of JavaScript developed by Micrpsoft.
  • Compiles to plain JavaScript.
  • Easily integrated into JavaScript projects.
  • Designed for development of large scale applications.

Static Type Checking


With typescript, we can check and assign variables, parameters, and function types.

TypeScript Types

  • String
  • Number
  • Boolean
  • Array
  • Any
  • Null
  • void
  • Tuple
  • Enum
  • Generics

Get Start using TypeScript with reactjs

To initialize project with boiler plate run this command
npx create-react-app my-app --template typescript

With Props


Alt Text
Alt Text

  • React.FC:React.FC show the Text component is functional component.
  • interface Props:We are defining types there.We can also pass object(Details) to our Props
  • App.tsx:We are passing everything in Text component.Missing anything will generate error

With hooks


Alt Text

So this was the small intro to use TypeScript with react.

Follow me on Github Shamaz Saeed

Top comments (2)

Collapse
 
calag4n profile image
calag4n β€’

Nice πŸ‘ πŸ™‚

Collapse
 
thearchitect profile image
Marcel Scherf β€’

Start using prettier to format your code. The inconsistency triggers my code-OCD.

SurveyJS custom survey software

JavaScript Form Builder UI Component

Generate dynamic JSON-driven forms directly in your JavaScript app (Angular, React, Vue.js, jQuery) with a fully customizable drag-and-drop form builder. Easily integrate with any backend system and retain full ownership over your data, with no user or form submission limits.

Learn more

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay