mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-06 02:33:53 -06:00
Add --strictPropertyInitialization compiler option
This commit is contained in:
parent
c11969f804
commit
8cbff0159d
@ -69,6 +69,7 @@ namespace ts {
|
||||
const allowSyntheticDefaultImports = getAllowSyntheticDefaultImports(compilerOptions);
|
||||
const strictNullChecks = getStrictOptionValue(compilerOptions, "strictNullChecks");
|
||||
const strictFunctionTypes = getStrictOptionValue(compilerOptions, "strictFunctionTypes");
|
||||
const strictPropertyInitialization = getStrictOptionValue(compilerOptions, "strictPropertyInitialization");
|
||||
const noImplicitAny = getStrictOptionValue(compilerOptions, "noImplicitAny");
|
||||
const noImplicitThis = getStrictOptionValue(compilerOptions, "noImplicitThis");
|
||||
|
||||
@ -22230,7 +22231,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
function checkPropertyInitialization(node: ClassLikeDeclaration) {
|
||||
if (!strictNullChecks || node.flags & NodeFlags.Ambient) {
|
||||
if (!strictNullChecks || !strictPropertyInitialization || node.flags & NodeFlags.Ambient) {
|
||||
return;
|
||||
}
|
||||
const constructor = findConstructorDeclaration(node);
|
||||
|
||||
@ -277,6 +277,13 @@ namespace ts {
|
||||
category: Diagnostics.Strict_Type_Checking_Options,
|
||||
description: Diagnostics.Enable_strict_checking_of_function_types
|
||||
},
|
||||
{
|
||||
name: "strictPropertyInitialization",
|
||||
type: "boolean",
|
||||
showInSimplifiedHelpView: true,
|
||||
category: Diagnostics.Strict_Type_Checking_Options,
|
||||
description: Diagnostics.Enable_strict_checking_of_property_initialization_in_classes
|
||||
},
|
||||
{
|
||||
name: "noImplicitThis",
|
||||
type: "boolean",
|
||||
|
||||
@ -1923,7 +1923,7 @@ namespace ts {
|
||||
: moduleKind === ModuleKind.System;
|
||||
}
|
||||
|
||||
export type StrictOptionName = "noImplicitAny" | "noImplicitThis" | "strictNullChecks" | "strictFunctionTypes" | "alwaysStrict";
|
||||
export type StrictOptionName = "noImplicitAny" | "noImplicitThis" | "strictNullChecks" | "strictFunctionTypes" | "strictPropertyInitialization" | "alwaysStrict";
|
||||
|
||||
export function getStrictOptionValue(compilerOptions: CompilerOptions, flag: StrictOptionName): boolean {
|
||||
return compilerOptions[flag] === undefined ? compilerOptions.strict : compilerOptions[flag];
|
||||
|
||||
@ -3330,6 +3330,10 @@
|
||||
"category": "Message",
|
||||
"code": 6186
|
||||
},
|
||||
"Enable strict checking of property initialization in classes.": {
|
||||
"category": "Message",
|
||||
"code": 6187
|
||||
},
|
||||
"Variable '{0}' implicitly has an '{1}' type.": {
|
||||
"category": "Error",
|
||||
"code": 7005
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user