Typescript is already installed and configured when generating a project with a javascript front.
-
Install typescript
yarn add --dev typescript
-
Install basic type definitions (pick what you need) which are not bundled with the dependencies on your project. All these types are referenced here
yarn add --dev
@types/cheerio
@types/enzyme
@types/history
@types/jest
@types/lodash
@types/node
@types/react
@types/react-dom
@types/react-intl
@types/react-redux
@types/react-router
@types/react-router-dom
@types/react-test-renderer
@types/styled-components
@types/superagent
@types/webpack-env
- Create basic Typescript config by copying tsconfig.json and tsconfig.paths.json
-
Install TSLint
yarn add --dev tslint
-
Create basic TSLint config by copying tslint.json
- about the deprecated no-unused-variable, see here why we keep it
-
Add linter checking commands
"lint": "tslint -c tslint.json 'src/**/*.{ts,tsx}'",
"lint:fix": "tslint -c tslint.json 'src/**/*.{ts,tsx}' --fix"
- Add the linter to your CI
- A Typescript file with JSX needs to have a .tsx extension (contrary to javascript where it is not necessary)
- Otherwise the extension should be .ts