yarn init -y
yarn add express
yarn add @types/express -D
yarn add typescript -D
yarn tsc --init
- Install ESLint extension in VS Code
- In the VSCode settings.json file:
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
}
yarn add eslint -D
yarn eslint --init
Example:
yarn add -D @typescript-eslint/eslint-plugin@latest eslint-config-airbnb-base@latest eslint-plugin-import@^2.22.1 @typescript-eslint/parser@latest
yarn add -D eslint-plugin-import-helpers eslint-import-resolver-typescript
Create file on root: .eslintignore
/*.js
node_modules
dist
Inside env
"jest": true
Next in extends "extends"
:
"plugin:@typescript-eslint/recommended"
Now, inside plugins:
"eslint-plugin-import-helpers"
Next, in rules:
"camelcase": "off",
"import/no-unresolved": "error",
"@typescript-eslint/naming-convention": [
"error",
{
"selector": "interface",
"format": ["PascalCase"],
"custom": {
"regex": "^I[A-Z]",
"match": true
}
}
],
"class-methods-use-this": "off",
"import/prefer-default-export": "off",
"no-shadow": "off",
"no-console": "off",
"no-useless-constructor": "off",
"no-empty-function": "off",
"lines-between-class-members": "off",
"import/extensions": [
"error",
"ignorePackages",
{
"ts": "never"
}
],
"import-helpers/order-imports": [
"warn",
{
"newlinesBetween": "always",
"groups": ["module", "/^@shared/", ["parent", "sibling", "index"]],
"alphabetize": { "order": "asc", "ignoreCase": true }
}
],
"import/no-extraneous-dependencies": [
"error",
{ "devDependencies": ["**/*.spec.js"] }
]
Now to node know Typescript:
"settings": {
"import/resolver": {
"typescript": {}
}
}
To finish and apply all the changes, let's close VS Code and reopen in the root folder of the project, otherwise ESLint will not recognize the installed dependencies and apply the Linting rules.
F
First we install the packages on the project.
yarn add prettier eslint-config-prettier eslint-plugin-prettier -D
Now we update the .eslintc.json, on extends:
"prettier",
"plugin:prettier/recommended"
plugins:
"prettier"
Rules:
"prettier/prettier": "error"
yarn add ts-node-dev -D
In the package.json, create a new script:
"scripts" : {
"dev": "ts-node-dev --transpile-only --ignore-watch node_modules --respawn src/server.ts"
}
On ts.config, delete strict, because now the responsability of errors of the app belongs to typescript:
// "strict": true,