Search code examples
typescriptpathoutputtsconfig

How is 'outDir' in tsconfig.json resolved?


Does baseUrl or current working directory affect it? And, more generally, where is this documented?


Solution

  • It does not seem to be documented anywhere, but it's resolved relative to the directory of tsconfig.json file, and it's not affected by baseUrl - baseUrl is for module resolution only.

    The source, slightly reformatted:

        const result = parseJsonText(configFileName, configFileText);
        const cwd = host.getCurrentDirectory();
        return parseJsonSourceFileConfigFileContent(
            result, 
            host, 
            getNormalizedAbsolutePath(getDirectoryPath(configFileName), cwd),
            optionsToExtend, 
            getNormalizedAbsolutePath(configFileName, cwd)
        );
    

    The third argument for parseJsonSourceFileConfigFileContent is the base for resolving relative paths in tsconfig.json, and as you see it comes from configFileName which is the name of tsconfig.json file.