Skip to content

GetResponse/tsconfig

Repository files navigation

@getresponse/tsconfig

License


This package contains a universal tsconfig file that is optimized for browser, library, and Node.js LTS projects. It can help you set up your TypeScript projects quickly and easily.

Compatibility

  • @getresponse/tsconfig@3.x - TypeScript >=6.0.0 <8.0.0
  • @getresponse/tsconfig@2.x - TypeScript >=6.0.0 <7.0.0 (no longer maintained)
  • @getresponse/tsconfig@1.x - TypeScript 5.x (no longer maintained)

Installation

  1. Install @getresponse/tsconfig as a development dependency:

    npm i --save-dev @getresponse/tsconfig
  2. Choose the appropriate config file for your project from @getresponse/tsconfig/configs:

  • For browser projects, use browser/tsconfig.json
  • For library projects with CommonJS modules, use lib/tsconfig.cjs.json
  • For library projects with ES modules, use lib/tsconfig.esm.json
  • For Node.js LTS projects, use either node-lts/tsconfig.cjs.json (CommonJS modules) or node-lts/tsconfig.json (ES modules)
  1. In your TypeScript configuration file (tsconfig.json), extend the chosen config file, for example (see documentation):

    {
         "extends": "@getresponse/tsconfig/configs/browser/tsconfig.json"
    }
  2. Optionally, customize the configuration options based on your project setup:

    • rootDir: set the root directory of your project (see rootDir)

    • include: specify which files should be included in the compilation process (see include)

    • exclude: specify which files should be excluded from the compilation process (see exclude)

    Here's an example with customized options:

    {
       "extends": "@getresponse/tsconfig/configs/browser/tsconfig.json",
       "compilerOptions": {
          "rootDir": "src"
       },
       "include": [
          "src/**/*",
          "types/**/*"
       ],
       "exclude": [
          "node_modules",
          "src/example-nested"
       ]
    }
  3. TypeScript 6 no longer auto-loads @types/* packages. If your project uses type definitions (e.g. @types/node, @types/react), add them explicitly in your tsconfig.json:

    {
       "extends": "@getresponse/tsconfig/configs/browser/tsconfig.json",
       "compilerOptions": {
          "types": ["react", "vite"]
       }
    }

    Note: node-lts configs already include "types": ["node"] by default.

  4. tsconfig.base.json, lib/tsconfig.esm.json, and node-lts/tsconfig.json use "moduleResolution": "nodenext", which requires:

    • "type": "module" in your project's package.json
    • explicit file extensions on relative imports, e.g. import { helper } from './helper.js' (not './helper'), even though the source file is helper.ts

    browser/tsconfig.json, lib/tsconfig.cjs.json, and node-lts/tsconfig.cjs.json use "moduleResolution": "bundler" instead and are not affected by either requirement.

That's it! Now you can enjoy the benefits of using a standardized tsconfig file in your TypeScript projects.

About

No description, website, or topics provided.

Resources

License

Stars

2 stars

Watchers

11 watching

Forks

Packages

 
 
 

Contributors