The Typescript Book

Notes on how to use the Typescript language

How to create a frontend development environment for Typescript

from node:alpine
workdir /usr/application
cmd ["npm", "start"]
copy package.json .
run npm install
copy . .

How to create a backend development environment for Typescript

FROM node:alpine
WORKDIR /usr/server
CMD ["npm", "run", "development"]
COPY package.json .
RUN npm install
COPY . .

Three cases where you need explicit type annotation

As a rule you should rely on type inference. In 3 specific cases you need to use explicit type annotation.

How to annotate a function

How to annotate an object

How to annotate a destructured value

How to annotate arrays

How to annotate tuples

How to create types in Typescript

How to create interfaces in Typescript

How to add method and property accessibility specifiers

How to use generics with constraints

How to use decorators

How to use React prop types with Typescript

How to use useRef instead of useState to represent a form

The usual approach for a form is to use state and set up change handlers on each input field. However this results on change handlers being fired on every keypress, potentially a large number of events. Since we are only interested in the contents of the input fields on a form submission, we can use refs to the input fields and only grab their values once when there is a form submission.

Last updated