diff --git a/linter-4.2/src/TypeScriptLinter.ts b/linter-4.2/src/TypeScriptLinter.ts index b1de4c2740b3836a43861ea9a081013a38d0e359..b5f624fc976be3176d3c77a39ed87a88d0a335bb 100644 --- a/linter-4.2/src/TypeScriptLinter.ts +++ b/linter-4.2/src/TypeScriptLinter.ts @@ -447,6 +447,17 @@ export class TypeScriptLinter { if (this.tsUtils.isDestructuringAssignmentLHS(objectLiteralExpr)) return; + // HACK: Relaxing rule for object literal typecheck, if object literal contained in structure + // declaration, than don't process it + // Very unoptimal, but in one place for later removal + let parent = node.parent; + while (parent !== null && parent !== undefined) { + if (LinterConfig.tsSyntaxKindNames[parent.kind] === 'StructDeclaration') { + return; + } + parent = parent.parent; + } + let objectLiteralType = this.tsTypeChecker.getContextualType(objectLiteralExpr); if (!this.tsUtils.areTypesAssignable(objectLiteralType, objectLiteralExpr)) this.incrementCounters(node, FaultID.ObjectLiteralNoContextType); diff --git a/linter/src/TypeScriptLinter.ts b/linter/src/TypeScriptLinter.ts index 9c1defffdea9f89c9a60752b1a41334177ca232f..73c808a65019a978cfc84953efbb78028946e9e0 100644 --- a/linter/src/TypeScriptLinter.ts +++ b/linter/src/TypeScriptLinter.ts @@ -464,6 +464,17 @@ export class TypeScriptLinter { if (this.tsUtils.isDestructuringAssignmentLHS(objectLiteralExpr)) return; + // HACK: Relaxing rule for object literal typecheck, if object literal contained in structure + // declaration, than don't process it + // Very unoptimal, but in one place for later removal + let parent = node.parent; + while (parent !== null && parent !== undefined) { + if (LinterConfig.tsSyntaxKindNames[parent.kind] === 'StructDeclaration') { + return; + } + parent = parent.parent; + } + let objectLiteralType = this.tsTypeChecker.getContextualType(objectLiteralExpr); if (!this.tsUtils.areTypesAssignable(objectLiteralType, objectLiteralExpr)) this.incrementCounters(node, FaultID.ObjectLiteralNoContextType);