Skip to content

Commit 535efd1

Browse files
Encode the conditional presence of 'error' in the type system.
1 parent 4b15c5f commit 535efd1

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

src/compiler/commandLineParser.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -327,11 +327,8 @@ namespace ts {
327327
if (hasProperty(map, key)) {
328328
options[opt.name] = map[key];
329329
}
330-
else if (opt.error) {
331-
errors.push(createCompilerDiagnostic(opt.error));
332-
}
333330
else {
334-
Debug.fail(`Command line option for '${opt.name}' doesn't account for invalid options.`);
331+
errors.push(createCompilerDiagnostic((<CommandLineOptionOfCustomType>opt).error));
335332
}
336333
}
337334
}
@@ -444,7 +441,7 @@ namespace ts {
444441
value = optType[key];
445442
}
446443
else {
447-
errors.push(createCompilerDiagnostic(opt.error));
444+
errors.push(createCompilerDiagnostic((<CommandLineOptionOfCustomType>opt).error));
448445
value = 0;
449446
}
450447
}

src/compiler/types.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2112,17 +2112,30 @@ namespace ts {
21122112
}
21132113

21142114
/* @internal */
2115-
export interface CommandLineOption {
2115+
interface CommandLineOptionBase {
21162116
name: string;
21172117
type: string | Map<number>; // "string", "number", "boolean", or an object literal mapping named values to actual values
21182118
isFilePath?: boolean; // True if option value is a path or fileName
21192119
shortName?: string; // A short mnemonic for convenience - for instance, 'h' can be used in place of 'help'
21202120
description?: DiagnosticMessage; // The message describing what the command line switch does
21212121
paramType?: DiagnosticMessage; // The name to be used for a non-boolean option's parameter
2122-
error?: DiagnosticMessage; // The error given when the argument does not fit a customized 'type'
21232122
experimental?: boolean;
21242123
}
21252124

2125+
/* @internal */
2126+
export interface CommandLineOptionOfPrimitiveType extends CommandLineOptionBase {
2127+
type: string; // "string" | "number" | "boolean"
2128+
}
2129+
2130+
/* @internal */
2131+
export interface CommandLineOptionOfCustomType extends CommandLineOptionBase {
2132+
type: Map<number>; // an object literal mapping named values to actual values
2133+
error: DiagnosticMessage; // The error given when the argument does not fit a customized 'type'
2134+
}
2135+
2136+
/* @internal */
2137+
export type CommandLineOption = CommandLineOptionOfCustomType | CommandLineOptionOfPrimitiveType;
2138+
21262139
/* @internal */
21272140
export const enum CharacterCodes {
21282141
nullCharacter = 0,

0 commit comments

Comments
 (0)