Skip to content

Instantly share code, notes, and snippets.

@khalidx
Created June 18, 2020 03:08
Show Gist options
  • Save khalidx/6155f6e6b0991b453dffcf98e571baeb to your computer and use it in GitHub Desktop.
Save khalidx/6155f6e6b0991b453dffcf98e571baeb to your computer and use it in GitHub Desktop.
Add a TypeScript config to your project easily

typescript config

Make sure to install the following dependencies for the best experience.

npm install --save tslib
npm install --save-dev typescript
npm install --save-dev ts-node

You can quickly generate a tsconfig.json with npx tsc --init.

Alternatively, here's a quick go-to file with sensible defaults and flags enabled (as of TypeScript v3.8.3).

{
  "compilerOptions": {
    "target": "ES2019",                       /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
    "module": "commonjs",                     /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
    "lib": ["ES2019"],                        /* Specify library files to be included in the compilation. */
    "declaration": true,                      /* Generates corresponding '.d.ts' file. */
    "declarationMap": true,                   /* Generates a sourcemap for each corresponding '.d.ts' file. */
    "sourceMap": true,                        /* Generates corresponding '.map' file. */
    "outDir": "./dist/",                      /* Redirect output structure to the directory. */
    "rootDir": "./src/",                      /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
    "importHelpers": true,                    /* Import emit helpers from 'tslib'. */
    /* Strict Type-Checking Options */
    "strict": true,                           /* Enable all strict type-checking options. */
    "noImplicitAny": true,                    /* Raise error on expressions and declarations with an implied 'any' type. */
    "strictNullChecks": true,                 /* Enable strict null checks. */
    "strictFunctionTypes": true,              /* Enable strict checking of function types. */
    "strictBindCallApply": true,              /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
    "strictPropertyInitialization": true,     /* Enable strict checking of property initialization in classes. */
    "noImplicitThis": true,                   /* Raise error on 'this' expressions with an implied 'any' type. */
    "alwaysStrict": true,                     /* Parse in strict mode and emit "use strict" for each source file. */
    /* Additional Checks */
    "noImplicitReturns": true,                /* Report error when not all code paths in function return a value. */
    "noFallthroughCasesInSwitch": true,       /* Report errors for fallthrough cases in switch statement. */
    /* Module Resolution Options */
    "moduleResolution": "node",               /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
    "esModuleInterop": true,                  /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
    /* Advanced Options */
    "forceConsistentCasingInFileNames": true  /* Disallow inconsistently-cased references to the same file. */
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment