Skip to content

Commit 8cbff01

Browse files
committed
Add --strictPropertyInitialization compiler option
1 parent c11969f commit 8cbff01

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

src/compiler/checker.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ namespace ts {
6969
const allowSyntheticDefaultImports = getAllowSyntheticDefaultImports(compilerOptions);
7070
const strictNullChecks = getStrictOptionValue(compilerOptions, "strictNullChecks");
7171
const strictFunctionTypes = getStrictOptionValue(compilerOptions, "strictFunctionTypes");
72+
const strictPropertyInitialization = getStrictOptionValue(compilerOptions, "strictPropertyInitialization");
7273
const noImplicitAny = getStrictOptionValue(compilerOptions, "noImplicitAny");
7374
const noImplicitThis = getStrictOptionValue(compilerOptions, "noImplicitThis");
7475

@@ -22230,7 +22231,7 @@ namespace ts {
2223022231
}
2223122232

2223222233
function checkPropertyInitialization(node: ClassLikeDeclaration) {
22233-
if (!strictNullChecks || node.flags & NodeFlags.Ambient) {
22234+
if (!strictNullChecks || !strictPropertyInitialization || node.flags & NodeFlags.Ambient) {
2223422235
return;
2223522236
}
2223622237
const constructor = findConstructorDeclaration(node);

src/compiler/commandLineParser.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,13 @@ namespace ts {
277277
category: Diagnostics.Strict_Type_Checking_Options,
278278
description: Diagnostics.Enable_strict_checking_of_function_types
279279
},
280+
{
281+
name: "strictPropertyInitialization",
282+
type: "boolean",
283+
showInSimplifiedHelpView: true,
284+
category: Diagnostics.Strict_Type_Checking_Options,
285+
description: Diagnostics.Enable_strict_checking_of_property_initialization_in_classes
286+
},
280287
{
281288
name: "noImplicitThis",
282289
type: "boolean",

src/compiler/core.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1923,7 +1923,7 @@ namespace ts {
19231923
: moduleKind === ModuleKind.System;
19241924
}
19251925

1926-
export type StrictOptionName = "noImplicitAny" | "noImplicitThis" | "strictNullChecks" | "strictFunctionTypes" | "alwaysStrict";
1926+
export type StrictOptionName = "noImplicitAny" | "noImplicitThis" | "strictNullChecks" | "strictFunctionTypes" | "strictPropertyInitialization" | "alwaysStrict";
19271927

19281928
export function getStrictOptionValue(compilerOptions: CompilerOptions, flag: StrictOptionName): boolean {
19291929
return compilerOptions[flag] === undefined ? compilerOptions.strict : compilerOptions[flag];

src/compiler/diagnosticMessages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3330,6 +3330,10 @@
33303330
"category": "Message",
33313331
"code": 6186
33323332
},
3333+
"Enable strict checking of property initialization in classes.": {
3334+
"category": "Message",
3335+
"code": 6187
3336+
},
33333337
"Variable '{0}' implicitly has an '{1}' type.": {
33343338
"category": "Error",
33353339
"code": 7005

0 commit comments

Comments
 (0)