Skip to content

Commit 28e3cd3

Browse files
authored
Add error on new module/moduleResolution modes when used in non-nightly TS (#46557)
* Add error on new module/moduleResolution modes when used in non-nightly TS * Update diagnostic
1 parent 9b1ba8f commit 28e3cd3

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/compiler/diagnosticMessages.json

+5
Original file line numberDiff line numberDiff line change
@@ -3778,6 +3778,11 @@
37783778
"category": "Error",
37793779
"code": 4123
37803780
},
3781+
"Compiler option '{0}' of value '{1}' is unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'.": {
3782+
"category": "Error",
3783+
"code": 4124
3784+
},
3785+
37813786
"The current host does not support the '{0}' option.": {
37823787
"category": "Error",
37833788
"code": 5001

src/compiler/program.ts

+17-2
Original file line numberDiff line numberDiff line change
@@ -3160,6 +3160,21 @@ namespace ts {
31603160
}
31613161

31623162
function verifyCompilerOptions() {
3163+
const isNightly = stringContains(version, "-dev");
3164+
if (!isNightly) {
3165+
if (getEmitModuleKind(options) === ModuleKind.Node12) {
3166+
createOptionValueDiagnostic("module", Diagnostics.Compiler_option_0_of_value_1_is_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next, "module", "node12");
3167+
}
3168+
else if (getEmitModuleKind(options) === ModuleKind.NodeNext) {
3169+
createOptionValueDiagnostic("module", Diagnostics.Compiler_option_0_of_value_1_is_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next, "module", "nodenext");
3170+
}
3171+
else if (getEmitModuleResolutionKind(options) === ModuleResolutionKind.Node12) {
3172+
createOptionValueDiagnostic("moduleResolution", Diagnostics.Compiler_option_0_of_value_1_is_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next, "moduleResolution", "node12");
3173+
}
3174+
else if (getEmitModuleResolutionKind(options) === ModuleResolutionKind.NodeNext) {
3175+
createOptionValueDiagnostic("moduleResolution", Diagnostics.Compiler_option_0_of_value_1_is_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next, "moduleResolution", "nodenext");
3176+
}
3177+
}
31633178
if (options.strictPropertyInitialization && !getStrictOptionValue(options, "strictNullChecks")) {
31643179
createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "strictPropertyInitialization", "strictNullChecks");
31653180
}
@@ -3696,8 +3711,8 @@ namespace ts {
36963711
createDiagnosticForOption(/*onKey*/ true, option1, option2, message, option1, option2, option3);
36973712
}
36983713

3699-
function createOptionValueDiagnostic(option1: string, message: DiagnosticMessage, arg0?: string) {
3700-
createDiagnosticForOption(/*onKey*/ false, option1, /*option2*/ undefined, message, arg0);
3714+
function createOptionValueDiagnostic(option1: string, message: DiagnosticMessage, arg0?: string, arg1?: string) {
3715+
createDiagnosticForOption(/*onKey*/ false, option1, /*option2*/ undefined, message, arg0, arg1);
37013716
}
37023717

37033718
function createDiagnosticForReference(sourceFile: JsonSourceFile | undefined, index: number, message: DiagnosticMessage, arg0?: string | number, arg1?: string | number) {

0 commit comments

Comments
 (0)