Skip to content
TheChatArchiveThe Chat Archive
Claudeclaude-sonnet-4-20250514-thinking-32k· AnthropicHugging Face LMArena Human Preference 140K

how to get output dir from tsconfig ?

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Geminigemini-2.5-flash’s answer.
  1. User

    how to get output dir from tsconfig ?

  2. Claude Assistant

    You can get the output directory from a TypeScript configuration file in several ways:

    Using TypeScript's API

    import * as ts from 'typescript';
    import * as path from 'path';
    
    // Read and parse tsconfig.json
    const configPath = ts.findConfigFile('./', ts.sys.fileExists, 'tsconfig.json');
    const configFile = ts.readConfigFile(configPath, ts.sys.readFile);
    const compilerOptions = ts.parseJsonConfigFileContent(configFile.config, ts.sys, './');
    
    // Get the output directory
    const outDir = compilerOptions.options.outDir || './dist'; // default fallback
    console.log('Output directory:', outDir);
    

    Using Node.js directly

    import fs from 'fs';
    import path from 'path';
    
    // Read tsconfig.json directly
    const tsconfigPath = path.resolve('./tsconfig.json');
    const tsconfig = JSON.parse(fs.readFileSync(tsconfigPath, 'utf8'));
    
    // Get outDir from compilerOptions
    const outDir = tsconfig.compilerOptions?.outDir || './dist';
    console.log('Output directory:', outDir);
    

    Using a library like get-tsconfig

    npm install get-tsconfig
    
    import { getTsconfig } from 'get-tsconfig';
    
    const tsconfig = getTsconfig('./tsconfig.json');
    const outDir = tsconfig?.config.compilerOptions?.outDir || './dist';
    console.log('Output directory:', outDir);
    

    In tsconfig.json

    The output directory is typically configured like this:

    {
      "compilerOptions": {
        "outDir": "./dist",
        "rootDir": "./src"
      }
    }
    

    The TypeScript API approach is most robust since it handles inheritance, path resolution, and all the complexities of TypeScript configuration parsing.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.