Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding -suppressExcessPropertyErrors compiler option #4484

Merged
merged 4 commits into from
Aug 27, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7161,7 +7161,7 @@ namespace ts {
let propertiesTable: SymbolTable = {};
let propertiesArray: Symbol[] = [];
let contextualType = getContextualType(node);
let typeFlags: TypeFlags;
let typeFlags: TypeFlags = 0;

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

function getIndexType(kind: IndexKind) {
Expand Down
6 changes: 6 additions & 0 deletions src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,12 @@ namespace ts {
description: Diagnostics.Specifies_the_location_where_debugger_should_locate_TypeScript_files_instead_of_source_locations,
paramType: Diagnostics.LOCATION,
},
{
name: "suppressExcessPropertyErrors",
type: "boolean",
description: Diagnostics.Suppress_excess_property_checks_for_object_literals,
experimental: true
},
{
name: "suppressImplicitAnyIndexErrors",
type: "boolean",
Expand Down
1 change: 1 addition & 0 deletions src/compiler/diagnosticInformationMap.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,7 @@ namespace ts {
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) ." },
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." },
Successfully_created_a_tsconfig_json_file: { code: 6071, category: DiagnosticCategory.Message, key: "Successfully created a tsconfig.json file." },
Suppress_excess_property_checks_for_object_literals: { code: 6072, category: DiagnosticCategory.Message, key: "Suppress excess property checks for object literals." },
Variable_0_implicitly_has_an_1_type: { code: 7005, category: DiagnosticCategory.Error, key: "Variable '{0}' implicitly has an '{1}' type." },
Parameter_0_implicitly_has_an_1_type: { code: 7006, category: DiagnosticCategory.Error, key: "Parameter '{0}' implicitly has an '{1}' type." },
Member_0_implicitly_has_an_1_type: { code: 7008, category: DiagnosticCategory.Error, key: "Member '{0}' implicitly has an '{1}' type." },
Expand Down
4 changes: 4 additions & 0 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -2266,6 +2266,10 @@
"category": "Message",
"code": 6071
},
"Suppress excess property checks for object literals.": {
"category": "Message",
"code": 6072
},

"Variable '{0}' implicitly has an '{1}' type.": {
"category": "Error",
Expand Down
1 change: 1 addition & 0 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2048,6 +2048,7 @@ namespace ts {
rootDir?: string;
sourceMap?: boolean;
sourceRoot?: string;
suppressExcessPropertyErrors?: boolean;
suppressImplicitAnyIndexErrors?: boolean;
target?: ScriptTarget;
version?: boolean;
Expand Down
6 changes: 5 additions & 1 deletion src/harness/harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1203,6 +1203,10 @@ module Harness {
options.isolatedModules = setting.value === "true";
break;

case "suppressexcesspropertyerrors":
options.suppressExcessPropertyErrors = setting.value === "true";
break;

case "suppressimplicitanyindexerrors":
options.suppressImplicitAnyIndexErrors = setting.value === "true";
break;
Expand Down Expand Up @@ -1569,7 +1573,7 @@ module Harness {
"nolib", "sourcemap", "target", "out", "outdir", "noemithelpers", "noemitonerror",
"noimplicitany", "noresolve", "newline", "normalizenewline", "emitbom",
"errortruncation", "usecasesensitivefilenames", "preserveconstenums",
"includebuiltfile", "suppressimplicitanyindexerrors", "stripinternal",
"includebuiltfile", "suppressexcesspropertyerrors", "suppressimplicitanyindexerrors", "stripinternal",
"isolatedmodules", "inlinesourcemap", "maproot", "sourceroot",
"inlinesources", "emitdecoratormetadata", "experimentaldecorators",
"skipdefaultlibcheck", "jsx"];
Expand Down
7 changes: 7 additions & 0 deletions tests/baselines/reference/excessPropertyErrorsSuppressed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//// [excessPropertyErrorsSuppressed.ts]

var x: { a: string } = { a: "hello", b: 42 }; // No error


//// [excessPropertyErrorsSuppressed.js]
var x = { a: "hello", b: 42 }; // No error
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
=== tests/cases/compiler/excessPropertyErrorsSuppressed.ts ===

var x: { a: string } = { a: "hello", b: 42 }; // No error
>x : Symbol(x, Decl(excessPropertyErrorsSuppressed.ts, 1, 3))
>a : Symbol(a, Decl(excessPropertyErrorsSuppressed.ts, 1, 8))
>a : Symbol(a, Decl(excessPropertyErrorsSuppressed.ts, 1, 24))
>b : Symbol(b, Decl(excessPropertyErrorsSuppressed.ts, 1, 36))

11 changes: 11 additions & 0 deletions tests/baselines/reference/excessPropertyErrorsSuppressed.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
=== tests/cases/compiler/excessPropertyErrorsSuppressed.ts ===

var x: { a: string } = { a: "hello", b: 42 }; // No error
>x : { a: string; }
>a : string
>{ a: "hello", b: 42 } : { a: string; b: number; }
>a : string
>"hello" : string
>b : number
>42 : number

3 changes: 3 additions & 0 deletions tests/cases/compiler/excessPropertyErrorsSuppressed.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//@suppressExcessPropertyErrors: true

var x: { a: string } = { a: "hello", b: 42 }; // No error