@@ -11925,7 +11925,7 @@ namespace ts {
1192511925 // on empty arrays are possible without implicit any errors and new element types can be inferred without
1192611926 // type mismatch errors.
1192711927 const resultType = getObjectFlags(evolvedType) & ObjectFlags.EvolvingArray && isEvolvingArrayOperationTarget(reference) ? anyArrayType : finalizeEvolvingArrayType(evolvedType);
11928- if (reference.parent.kind === SyntaxKind.NonNullExpression && getTypeWithFacts(resultType, TypeFacts.NEUndefinedOrNull).flags & TypeFlags.Never) {
11928+ if (reference.parent && reference.parent .kind === SyntaxKind.NonNullExpression && getTypeWithFacts(resultType, TypeFacts.NEUndefinedOrNull).flags & TypeFlags.Never) {
1192911929 return declaredType;
1193011930 }
1193111931 return resultType;
@@ -22072,6 +22072,7 @@ namespace ts {
2207222072 if (produceDiagnostics) {
2207322073 checkIndexConstraints(type);
2207422074 checkTypeForDuplicateIndexSignatures(node);
22075+ checkPropertyInitialization(node);
2207522076 }
2207622077 }
2207722078
@@ -22228,6 +22229,33 @@ namespace ts {
2222822229 return ok;
2222922230 }
2223022231
22232+ function checkPropertyInitialization(node: ClassLikeDeclaration) {
22233+ if (!strictNullChecks || node.flags & NodeFlags.Ambient) {
22234+ return;
22235+ }
22236+ const constructor = findConstructorDeclaration(node);
22237+ for (const member of node.members) {
22238+ if (member.kind === SyntaxKind.PropertyDeclaration && !(<PropertyDeclaration>member).initializer) {
22239+ const propName = (<PropertyDeclaration>member).name;
22240+ if (isIdentifier(propName)) {
22241+ const type = getTypeOfSymbol(getSymbolOfNode(member));
22242+ if (!(type.flags & TypeFlags.Any || getFalsyFlags(type) & TypeFlags.Undefined)) {
22243+ if (!constructor || !isPropertyInitializedInConstructor(propName, type, constructor)) {
22244+ error(member.name, Diagnostics.Property_0_has_no_initializer_and_is_not_definitely_assigned_in_the_constructor, declarationNameToString(propName));
22245+ }
22246+ }
22247+ }
22248+ }
22249+ }
22250+ }
22251+
22252+ function isPropertyInitializedInConstructor(propName: Identifier, propType: Type, constructor: ConstructorDeclaration) {
22253+ const reference = createPropertyAccess(createThis(), propName);
22254+ reference.flowNode = constructor.returnFlowNode;
22255+ const flowType = getFlowTypeOfReference(reference, propType, getOptionalType(propType));
22256+ return !(getFalsyFlags(flowType) & TypeFlags.Undefined);
22257+ }
22258+
2223122259 function checkInterfaceDeclaration(node: InterfaceDeclaration) {
2223222260 // Grammar checking
2223322261 if (!checkGrammarDecoratorsAndModifiers(node)) checkGrammarInterfaceDeclaration(node);
0 commit comments