{"record":{"id":"dab60a1b70d6b529","repo":"microsoft/TypeScript","slug":"cannot-have-undefined-value-for-compiler-option","errorCode":null,"errorMessage":"Cannot have undefined value for compiler option '${name}'.","messagePattern":"Cannot have undefined value for compiler option '(.+?)'\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/harness/harnessIO.ts","lineNumber":284,"sourceCode":"\r\n    let optionsIndex: Map<string, ts.CommandLineOption>;\r\n    function getCommandLineOption(name: string): ts.CommandLineOption | undefined {\r\n        if (!optionsIndex) {\r\n            optionsIndex = new Map<string, ts.CommandLineOption>();\r\n            const optionDeclarations = harnessOptionDeclarations.concat(ts.optionDeclarations);\r\n            for (const option of optionDeclarations) {\r\n                optionsIndex.set(option.name.toLowerCase(), option);\r\n            }\r\n        }\r\n        return optionsIndex.get(name.toLowerCase());\r\n    }\r\n\r\n    export function setCompilerOptionsFromHarnessSetting(settings: TestCaseParser.CompilerSettings, options: ts.CompilerOptions & HarnessOptions): void {\r\n        for (const name in settings) {\r\n            if (ts.hasProperty(settings, name)) {\r\n                const value = settings[name];\r\n                if (value === undefined) {\r\n                    throw new Error(`Cannot have undefined value for compiler option '${name}'.`);\r\n                }\r\n                if (name === \"typeScriptVersion\") {\r\n                    continue;\r\n                }\r\n                const option = getCommandLineOption(name);\r\n                if (option) {\r\n                    const errors: ts.Diagnostic[] = [];\r\n                    options[option.name] = optionValue(option, value, errors);\r\n                    if (errors.length > 0) {\r\n                        throw new Error(`Unknown value '${value}' for compiler option '${name}'.`);\r\n                    }\r\n                }\r\n                else {\r\n                    throw new Error(`Unknown compiler option '${name}'.`);\r\n                }\r\n            }\r\n        }\r\n    }\r","sourceCodeStart":266,"sourceCodeEnd":302,"githubUrl":"https://github.com/microsoft/TypeScript/blob/b465fdbfe175304d9b977da137b2c178ae1091d3/src/harness/harnessIO.ts#L266-L302","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Provide a concrete value for the named compiler option in the test configuration.","If the option should not be set, delete the key from the settings object rather than leaving it undefined.","Audit the code that builds CompilerSettings to ensure it only includes keys with defined values."],"exampleFix":"// before\nconst settings = { target: undefined };\nHarness.IO.setCompilerOptionsFromHarnessSetting(settings, options);\n// after\ndelete settings.target;\nHarness.IO.setCompilerOptionsFromHarnessSetting(settings, options);","handlingStrategy":"validation","validationCode":"function stripUndefined(settings: Record<string, unknown>) {\n    for (const key of Object.keys(settings)) {\n        if (settings[key] === undefined) delete settings[key];\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Build CompilerSettings by only assigning keys with concrete values.","Audit shared config helpers to ensure they omit unset keys instead of writing undefined."],"tags":["harness","compiler-options","configuration","undefined-value"],"backgroundTag":null,"analyzedSha":"b465fdbfe175304d9b977da137b2c178ae1091d3","analyzedAt":"2026-08-12T05:38:42.698Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}