microsoft/TypeScript · error · Error

Cannot have undefined value for compiler option '${name}'.

Error message

Cannot have undefined value for compiler option '${name}'.

What it means

Thrown by setCompilerOptionsFromHarnessSetting when iterating compiler settings from a test's harness configuration and a setting value is undefined. The harness reads each key from the TestCaseParser.CompilerSettings object and rejects undefined because it cannot map it onto a CommandLineOption.

Source

Thrown at src/harness/harnessIO.ts:284

    let optionsIndex: Map<string, ts.CommandLineOption>;
    function getCommandLineOption(name: string): ts.CommandLineOption | undefined {
        if (!optionsIndex) {
            optionsIndex = new Map<string, ts.CommandLineOption>();
            const optionDeclarations = harnessOptionDeclarations.concat(ts.optionDeclarations);
            for (const option of optionDeclarations) {
                optionsIndex.set(option.name.toLowerCase(), option);
            }
        }
        return optionsIndex.get(name.toLowerCase());
    }

    export function setCompilerOptionsFromHarnessSetting(settings: TestCaseParser.CompilerSettings, options: ts.CompilerOptions & HarnessOptions): void {
        for (const name in settings) {
            if (ts.hasProperty(settings, name)) {
                const value = settings[name];
                if (value === undefined) {
                    throw new Error(`Cannot have undefined value for compiler option '${name}'.`);
                }
                if (name === "typeScriptVersion") {
                    continue;
                }
                const option = getCommandLineOption(name);
                if (option) {
                    const errors: ts.Diagnostic[] = [];
                    options[option.name] = optionValue(option, value, errors);
                    if (errors.length > 0) {
                        throw new Error(`Unknown value '${value}' for compiler option '${name}'.`);
                    }
                }
                else {
                    throw new Error(`Unknown compiler option '${name}'.`);
                }
            }
        }
    }

View on GitHub (pinned to b465fdbfe1)

Solutions

  1. Provide a concrete value for the named compiler option in the test configuration.
  2. If the option should not be set, delete the key from the settings object rather than leaving it undefined.
  3. Audit the code that builds CompilerSettings to ensure it only includes keys with defined values.

Example fix

// before
const settings = { target: undefined };
Harness.IO.setCompilerOptionsFromHarnessSetting(settings, options);
// after
delete settings.target;
Harness.IO.setCompilerOptionsFromHarnessSetting(settings, options);
Defensive patterns

Strategy: validation

Validate before calling

function stripUndefined(settings: Record<string, unknown>) {
    for (const key of Object.keys(settings)) {
        if (settings[key] === undefined) delete settings[key];
    }
}

Prevention

When it happens

Trigger: A test configuration (CompilerSettings) contains a key whose value is undefined — e.g. the setting was declared but assigned no value, or destructured in a way that produced undefined.

Common situations: Test author writes a setting key with no value, programmatically builds a settings object that may omit values, or a shared config helper injects undefined for an unset option instead of omitting the key entirely.

Related errors


AI-assisted analysis of microsoft/TypeScript@b465fdbfe1 (2026-08-12). Data as JSON: /api/errors/dab60a1b70d6b529. Report an issue: GitHub.