Skip to content

Commit c56683c

Browse files
committed
Merge pull request #4484 from Microsoft/suppressExcessPropertyErrors
Adding -suppressExcessPropertyErrors compiler option
2 parents 6fbf449 + 806c549 commit c56683c

10 files changed

+49
-3
lines changed

Diff for: src/compiler/checker.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -7161,7 +7161,7 @@ namespace ts {
71617161
let propertiesTable: SymbolTable = {};
71627162
let propertiesArray: Symbol[] = [];
71637163
let contextualType = getContextualType(node);
7164-
let typeFlags: TypeFlags;
7164+
let typeFlags: TypeFlags = 0;
71657165

71667166
for (let memberDecl of node.properties) {
71677167
let member = memberDecl.symbol;
@@ -7210,7 +7210,8 @@ namespace ts {
72107210
let stringIndexType = getIndexType(IndexKind.String);
72117211
let numberIndexType = getIndexType(IndexKind.Number);
72127212
let result = createAnonymousType(node.symbol, propertiesTable, emptyArray, emptyArray, stringIndexType, numberIndexType);
7213-
result.flags |= TypeFlags.ObjectLiteral | TypeFlags.FreshObjectLiteral | TypeFlags.ContainsObjectLiteral | (typeFlags & TypeFlags.PropagatingFlags);
7213+
let freshObjectLiteralFlag = compilerOptions.suppressExcessPropertyErrors ? 0 : TypeFlags.FreshObjectLiteral;
7214+
result.flags |= TypeFlags.ObjectLiteral | TypeFlags.ContainsObjectLiteral | freshObjectLiteralFlag | (typeFlags & TypeFlags.PropagatingFlags);
72147215
return result;
72157216

72167217
function getIndexType(kind: IndexKind) {

Diff for: src/compiler/commandLineParser.ts

+6
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,12 @@ namespace ts {
184184
description: Diagnostics.Specifies_the_location_where_debugger_should_locate_TypeScript_files_instead_of_source_locations,
185185
paramType: Diagnostics.LOCATION,
186186
},
187+
{
188+
name: "suppressExcessPropertyErrors",
189+
type: "boolean",
190+
description: Diagnostics.Suppress_excess_property_checks_for_object_literals,
191+
experimental: true
192+
},
187193
{
188194
name: "suppressImplicitAnyIndexErrors",
189195
type: "boolean",

Diff for: src/compiler/diagnosticInformationMap.generated.ts

+1
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,7 @@ namespace ts {
569569
Specifies_module_resolution_strategy_Colon_node_Node_or_classic_TypeScript_pre_1_6: { code: 6069, category: DiagnosticCategory.Message, key: "Specifies module resolution strategy: 'node' (Node) or 'classic' (TypeScript pre 1.6) ." },
570570
Initializes_a_TypeScript_project_and_creates_a_tsconfig_json_file: { code: 6070, category: DiagnosticCategory.Message, key: "Initializes a TypeScript project and creates a tsconfig.json file." },
571571
Successfully_created_a_tsconfig_json_file: { code: 6071, category: DiagnosticCategory.Message, key: "Successfully created a tsconfig.json file." },
572+
Suppress_excess_property_checks_for_object_literals: { code: 6072, category: DiagnosticCategory.Message, key: "Suppress excess property checks for object literals." },
572573
Variable_0_implicitly_has_an_1_type: { code: 7005, category: DiagnosticCategory.Error, key: "Variable '{0}' implicitly has an '{1}' type." },
573574
Parameter_0_implicitly_has_an_1_type: { code: 7006, category: DiagnosticCategory.Error, key: "Parameter '{0}' implicitly has an '{1}' type." },
574575
Member_0_implicitly_has_an_1_type: { code: 7008, category: DiagnosticCategory.Error, key: "Member '{0}' implicitly has an '{1}' type." },

Diff for: src/compiler/diagnosticMessages.json

+4
Original file line numberDiff line numberDiff line change
@@ -2266,6 +2266,10 @@
22662266
"category": "Message",
22672267
"code": 6071
22682268
},
2269+
"Suppress excess property checks for object literals.": {
2270+
"category": "Message",
2271+
"code": 6072
2272+
},
22692273

22702274
"Variable '{0}' implicitly has an '{1}' type.": {
22712275
"category": "Error",

Diff for: src/compiler/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -2048,6 +2048,7 @@ namespace ts {
20482048
rootDir?: string;
20492049
sourceMap?: boolean;
20502050
sourceRoot?: string;
2051+
suppressExcessPropertyErrors?: boolean;
20512052
suppressImplicitAnyIndexErrors?: boolean;
20522053
target?: ScriptTarget;
20532054
version?: boolean;

Diff for: src/harness/harness.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -1203,6 +1203,10 @@ module Harness {
12031203
options.isolatedModules = setting.value === "true";
12041204
break;
12051205

1206+
case "suppressexcesspropertyerrors":
1207+
options.suppressExcessPropertyErrors = setting.value === "true";
1208+
break;
1209+
12061210
case "suppressimplicitanyindexerrors":
12071211
options.suppressImplicitAnyIndexErrors = setting.value === "true";
12081212
break;
@@ -1567,7 +1571,7 @@ module Harness {
15671571
"nolib", "sourcemap", "target", "out", "outdir", "noemithelpers", "noemitonerror",
15681572
"noimplicitany", "noresolve", "newline", "normalizenewline", "emitbom",
15691573
"errortruncation", "usecasesensitivefilenames", "preserveconstenums",
1570-
"includebuiltfile", "suppressimplicitanyindexerrors", "stripinternal",
1574+
"includebuiltfile", "suppressexcesspropertyerrors", "suppressimplicitanyindexerrors", "stripinternal",
15711575
"isolatedmodules", "inlinesourcemap", "maproot", "sourceroot",
15721576
"inlinesources", "emitdecoratormetadata", "experimentaldecorators",
15731577
"skipdefaultlibcheck", "jsx"];
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//// [excessPropertyErrorsSuppressed.ts]
2+
3+
var x: { a: string } = { a: "hello", b: 42 }; // No error
4+
5+
6+
//// [excessPropertyErrorsSuppressed.js]
7+
var x = { a: "hello", b: 42 }; // No error
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
=== tests/cases/compiler/excessPropertyErrorsSuppressed.ts ===
2+
3+
var x: { a: string } = { a: "hello", b: 42 }; // No error
4+
>x : Symbol(x, Decl(excessPropertyErrorsSuppressed.ts, 1, 3))
5+
>a : Symbol(a, Decl(excessPropertyErrorsSuppressed.ts, 1, 8))
6+
>a : Symbol(a, Decl(excessPropertyErrorsSuppressed.ts, 1, 24))
7+
>b : Symbol(b, Decl(excessPropertyErrorsSuppressed.ts, 1, 36))
8+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
=== tests/cases/compiler/excessPropertyErrorsSuppressed.ts ===
2+
3+
var x: { a: string } = { a: "hello", b: 42 }; // No error
4+
>x : { a: string; }
5+
>a : string
6+
>{ a: "hello", b: 42 } : { a: string; b: number; }
7+
>a : string
8+
>"hello" : string
9+
>b : number
10+
>42 : number
11+
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
//@suppressExcessPropertyErrors: true
2+
3+
var x: { a: string } = { a: "hello", b: 42 }; // No error

0 commit comments

Comments
 (0)