Skip to content

Commit 7031c43

Browse files
committed
correctly detect if strictNullChecks is enabled
Fixes: #25808
1 parent 1cedab1 commit 7031c43

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

src/compiler/program.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2366,7 +2366,7 @@ namespace ts {
23662366
}
23672367

23682368
function verifyCompilerOptions() {
2369-
if (options.strictPropertyInitialization && !options.strictNullChecks) {
2369+
if (options.strictPropertyInitialization && !getStrictOptionValue(options, "strictNullChecks")) {
23702370
createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "strictPropertyInitialization", "strictNullChecks");
23712371
}
23722372

src/testRunner/unittests/convertCompilerOptionsFromJson.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,51 @@ namespace ts {
436436
);
437437
});
438438

439+
it("Correctly detects implicitly enabled strictNullChecks ", () => {
440+
assertCompilerOptions(
441+
{
442+
compilerOptions: {
443+
strict: true,
444+
strictPropertyInitialization: true
445+
}
446+
}, "tsconfig.json",
447+
{
448+
compilerOptions: {
449+
strict: true,
450+
strictPropertyInitialization: true
451+
},
452+
errors: []
453+
}
454+
);
455+
});
456+
457+
it("Checks dependency of strict options ", () => {
458+
assertCompilerOptions(
459+
{
460+
compilerOptions: {
461+
strict: true,
462+
strictNullChecks: false,
463+
strictPropertyInitialization: true
464+
}
465+
}, "tsconfig.json",
466+
{
467+
compilerOptions: {
468+
strict: true,
469+
strictNullChecks: false,
470+
strictPropertyInitialization: true
471+
},
472+
errors: [{
473+
file: undefined,
474+
start: 0,
475+
length: 0,
476+
messageText: "Option 'strictPropertyInitialization' cannot be specified without specifying option 'strictNullChecks'.",
477+
code: Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1.code,
478+
category: Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1.category
479+
}]
480+
}
481+
);
482+
});
483+
439484
// jsconfig.json
440485
it("Convert correctly format jsconfig.json to compiler-options ", () => {
441486
assertCompilerOptions(

0 commit comments

Comments
 (0)