# TypeScript
# React & TypeScript
In
create-react-app
there is a TS boilerplate. To create it, we need to append--template typescript
to the script. Example:npx create-react-app testing --template typescript
.When we declare a function or class component, we need to specify it in TS, so that we can get types for
React.Children
, for example. In a function component, we would do that like this:const Hey<React.FC>
.We can use
as
to tell TS the types, in cases where "we know better" than TS's type inference. This is common practice in cases where we have anever[]
type and then we can fixing by writingas MyArray[]
.When we give TS an array, it will assume that the array is out of order. We can tell it which order the elements inside it will be (with
as
).