DEV Community

j1ngzoue
j1ngzoue

Posted on • Edited on

2 1

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

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs