DEV Community

j1ngzoue
j1ngzoue

Posted on • Updated on

Use tsconfck to verify the final configuration of tsconfig.json

When you're touching a typescript project, you may want to see what your tsconfig will look like in the end. Currently, the typescipt package does not provide an API for checking.

In vite, I used a project called tsconfck to get the final configuration of tsconfig.json, so let's touch it.

https://github.com/dominikg/tsconfck

Prepare the following tsconfig file and execute parseNative from js.

{
  "compilerOptions": {
    "target": "esnext",
    "module": "commonjs",
    "baseUrl": "src",
    "declaration": true,
    "outDir": "./dist/",
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "skipLibCheck": true
  },
  "exclude": ["node_modules", "example/*", "dist/*"]
}
Enter fullscreen mode Exit fullscreen mode
import { parseNative } from 'tsconfck';

export const main = async () => {
  const tsConfigFile= await parseNative('index.ts');
  console.log('tsConfigFile :>> ', tsConfigFile);
};

main();
Enter fullscreen mode Exit fullscreen mode

You can get the final configuration file as an object.
You can get a result similar to the result output below in the typescript code.
https://github.com/microsoft/TypeScript/blob/95ef2a503dd0cae9f106948cccee8a041078a472/src/executeCommandLine/executeCommandLine.ts#L529

tsConfigFile :>>  {
  tsconfigFile: '/Users/j1ingzoue/projects/tsconfck/tsconfig.json',
  tsconfig: {
    compilerOptions: {
      target: 'latest',
      module: 'commonjs',
      baseUrl: '/Users/j1ingzoue/projects/tsconfck/src',
      declaration: true,
      outDir: '/Users/j1ingzoue/projects/tsconfck/dist',
      esModuleInterop: true,
      forceConsistentCasingInFileNames: true,
      strict: true,
      skipLibCheck: true
    },
    exclude: [ 'node_modules', 'example/*', 'dist/*' ]
  },
  result: {
    options: {
      target: 99,
      module: 1,
      baseUrl: '/Users/j1ingzoue/projects/tsconfck/src',
      declaration: true,
      outDir: '/Users/j1ingzoue/projects/tsconfck/dist',
      esModuleInterop: true,
      forceConsistentCasingInFileNames: true,
      strict: true,
      skipLibCheck: true,
      configFilePath: '/Users/j1ingzoue/projects/tsconfck/tsconfig.json'
    },
    watchOptions: undefined,
    fileNames: [ '/Users/j1ingzoue/projects/tsconfck/index.ts' ],
    projectReferences: undefined,
    typeAcquisition: { enable: false, include: [], exclude: [] },
    raw: {
      compilerOptions: [Object],
      exclude: [Array],
      compileOnSave: false
    },
    errors: [],
    wildcardDirectories: { '/users/j1ingzoue/projects/tsconfck': 1 },
    compileOnSave: false
  }
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)