Skip to content

Instantly share code, notes, and snippets.

@aaabramov
Created June 29, 2022 13:06
Show Gist options
  • Save aaabramov/ad1934c5740b018f172e6d82f629b105 to your computer and use it in GitHub Desktop.
Save aaabramov/ad1934c5740b018f172e6d82f629b105 to your computer and use it in GitHub Desktop.
Bootstrap TypeScript npm project

Init project:

npm init

Install typescript & @types

npm install --save-dev \
  typescript \
  @types/node \
  @types/jest

Create tsconfig.json

{
  "compilerOptions": {
    "module": "commonjs",
    "declaration": true,
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "allowSyntheticDefaultImports": true,
    "target": "es2017",
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./",
    "incremental": true,
    "skipLibCheck": true,
    "strictNullChecks": false,
    "noImplicitAny": false,
    "strictBindCallApply": false,
    "forceConsistentCasingInFileNames": false,
    "noFallthroughCasesInSwitch": false
  }
}

Linting TypeScript with ESLint

npm install --save-dev \
  eslint \
  @typescript-eslint/parser \
  @typescript-eslint/eslint-plugin \
  eslint-config-prettier \
  eslint-plugin-prettier \
  prettier

ESLint & prettier config

.eslintrc.js:

module.exports = {
  parser: '@typescript-eslint/parser',
  parserOptions: {
    project: 'tsconfig.json',
    tsconfigRootDir : __dirname, 
    sourceType: 'module',
  },
  plugins: ['@typescript-eslint/eslint-plugin'],
  extends: [
    'plugin:@typescript-eslint/recommended',
    'plugin:prettier/recommended',
  ],
  root: true,
  env: {
    node: true,
    jest: true,
  },
  ignorePatterns: ['.eslintrc.js'],
  rules: {
    '@typescript-eslint/interface-name-prefix': 'off',
    '@typescript-eslint/explicit-function-return-type': 'off',
    '@typescript-eslint/explicit-module-boundary-types': 'off',
    '@typescript-eslint/no-explicit-any': 'off',
  },
};

.prettierrc:

{
  "singleQuote": true,
  "trailingComma": "all"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment