Skip to content

Instantly share code, notes, and snippets.

@rpivo
Last active March 15, 2021 12:10
Show Gist options
  • Save rpivo/fc4d24141b0b967ca5bc5e04c67e6e84 to your computer and use it in GitHub Desktop.
Save rpivo/fc4d24141b0b967ca5bc5e04c67e6e84 to your computer and use it in GitHub Desktop.
My TS Config Template

My TS Config Template

This is my starter tsconfig that I use for React / TypeScript applications. See further down the gist for a version without comments.

{
  "compilerOptions": {
    // source code will be kept in this location
    "baseUrl": "./src",
    // allows possible commonjs imports to be used inside an ES module context
    "esModuleInterop": true,
    // disallow inconsistently-cased references to the same file.
    "forceConsistentCasingInFileNames": true,
    // support JSX in TSX files
    "jsx": "react",
    // allow next-gen JS in source code
    "module": "esnext",
    // helps TS recognize Node-style imports
    "moduleResolution": "node",
    // prevent use of any type
    "noImplicitAny": true,
    // require return types
    "noImplicitReturns": true,
    // use the relative path @components/* for importing components into files
    // can add more relative paths here as needed
    "paths": {
      "@components/*": ["components/*"],
    },
    // include modules imported with .json extension
    "resolveJsonModule": true,
    // enable all strict type checking options
    "strict": true,
    // compile to ESNext
    // this should be bumped down as needed (likely down to ES5 for larger, less experimental apps)
    "target": "esnext",
  }
}

Without comments:

{
  "compilerOptions": {
    "baseUrl": "./src",
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "jsx": "react",
    "module": "esnext",
    "moduleResolution": "node",
    "noImplicitAny": true,
    "noImplicitReturns": true,
    "paths": {
      "@components/*": ["components/*"],
    },
    "resolveJsonModule": true,
    "strict": true,
    "target": "esnext",
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment