microsoft/TypeScript · error · Error

Value must be a number, got: ${JSON.stringify(value)}

Error message

Value must be a number, got: ${JSON.stringify(value)}

What it means

Thrown by optionValue when a compiler option declared with type 'number' receives a string that parseInt(value, 10) cannot parse (result isNaN). This is the numeric branch of the option-value parser invoked from setCompilerOptionsFromHarnessSetting.

Source

Thrown at src/harness/harnessIO.ts:313

                    }
                }
                else {
                    throw new Error(`Unknown compiler option '${name}'.`);
                }
            }
        }
    }

    function optionValue(option: ts.CommandLineOption, value: string, errors: ts.Diagnostic[]): any {
        switch (option.type) {
            case "boolean":
                return value.toLowerCase() === "true";
            case "string":
                return value;
            case "number": {
                const numverValue = parseInt(value, 10);
                if (isNaN(numverValue)) {
                    throw new Error(`Value must be a number, got: ${JSON.stringify(value)}`);
                }
                return numverValue;
            }
            // If not a primitive, the possible types are specified in what is effectively a map of options.
            case "list":
            case "listOrElement":
                return ts.parseListTypeOption(option, value, errors);
            default:
                return ts.parseCustomTypeOption(option as ts.CommandLineOptionOfCustomType, value, errors);
        }
    }

    export interface TestFile {
        unitName: string;
        content: string;
        fileOptions?: any;
    }

View on GitHub (pinned to b465fdbfe1)

Solutions

  1. Confirm the option expects a number (check its type in optionDeclarations) and supply a numeric string.
  2. Remove any non-numeric characters (units, suffixes) from the value.
  3. If the option is actually an enum/map type, the harness optionDeclarations may need correcting rather than the value.

Example fix

// before
// @maxNodeModuleJsDepth: deep
// after
// @maxNodeModuleJsDepth: 2
Defensive patterns

Strategy: validation

Validate before calling

function validateNumericOption(value: string) {
    if (Number.isNaN(parseInt(value, 10))) {
        throw new Error(`'${value}' is not numeric`);
    }
}

Prevention

When it happens

Trigger: A test setting assigns a non-numeric string to a number-typed option, e.g. @target: 'esnext' on a numeric option, or @someNumberOption: 'abc'. The value arrives as a raw string from the test config.

Common situations: Misidentifying an option's type, supplying a textual value where a numeric one is expected, or a stray non-digit character in the value.

Related errors


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