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

Suppress no implicit any errors #1418

Merged
merged 5 commits into from
Dec 11, 2014
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
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5335,7 +5335,7 @@ module ts {
}

// Fall back to any.
if (compilerOptions.noImplicitAny && objectType !== anyType) {
if (compilerOptions.noImplicitAny && !compilerOptions.suppressImplicitAnyIndexErrors && objectType !== anyType) {
error(node, Diagnostics.Index_signature_of_object_type_implicitly_has_an_any_type);
}

Expand Down
17 changes: 11 additions & 6 deletions src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ module ts {
description: Diagnostics.Redirect_output_structure_to_the_directory,
paramType: Diagnostics.DIRECTORY,
},
{
name: "preserveConstEnums",
type: "boolean",
description: Diagnostics.Do_not_erase_const_enum_declarations_in_generated_code
},
{
name: "removeComments",
type: "boolean",
Expand All @@ -104,6 +109,11 @@ module ts {
description: Diagnostics.Specifies_the_location_where_debugger_should_locate_TypeScript_files_instead_of_source_locations,
paramType: Diagnostics.LOCATION,
},
{
name: "suppressImplicitAnyIndexErrors",
type: "boolean",
description: Diagnostics.Suppress_noImplicitAny_errors_for_indexing_objects_lacking_index_signatures,
},
{
name: "target",
shortName: "t",
Expand All @@ -124,13 +134,8 @@ module ts {
type: "boolean",
description: Diagnostics.Watch_input_files,
},
{
name: "preserveConstEnums",
type: "boolean",
description: Diagnostics.Do_not_erase_const_enum_declarations_in_generated_code
}
];

var shortOptionNames: Map<string> = {};
var optionNameMap: Map<CommandLineOption> = {};

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 @@ -411,6 +411,7 @@ module ts {
Warn_on_expressions_and_declarations_with_an_implied_any_type: { code: 6052, category: DiagnosticCategory.Message, key: "Warn on expressions and declarations with an implied 'any' type." },
File_0_not_found: { code: 6053, category: DiagnosticCategory.Error, key: "File '{0}' not found." },
File_0_must_have_extension_ts_or_d_ts: { code: 6054, category: DiagnosticCategory.Error, key: "File '{0}' must have extension '.ts' or '.d.ts'." },
Suppress_noImplicitAny_errors_for_indexing_objects_lacking_index_signatures: { code: 6055, category: DiagnosticCategory.Message, key: "Suppress noImplicitAny errors for indexing objects lacking index signatures." },
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 @@ -1643,6 +1643,10 @@
"category": "Error",
"code": 6054
},
"Suppress noImplicitAny errors for indexing objects lacking index signatures.": {
"category": "Message",
"code": 6055
},

"Variable '{0}' implicitly has an '{1}' type.": {
"category": "Error",
Expand Down
10 changes: 5 additions & 5 deletions src/compiler/tsc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,12 +378,12 @@ module ts {
var usageText = " ";
if (option.shortName) {
usageText += "-" + option.shortName;
usageText += getParamName(option);
usageText += getParamType(option);
usageText += ", ";
}

usageText += "--" + option.name;
usageText += getParamName(option);
usageText += getParamType(option);

usageColumn.push(usageText);
descriptionColumn.push(getDiagnosticText(option.description));
Expand All @@ -408,9 +408,9 @@ module ts {
sys.write(output);
return;

function getParamName(option: CommandLineOption) {
if (option.paramName !== undefined) {
return " " + getDiagnosticText(option.paramName);
function getParamType(option: CommandLineOption) {
if (option.paramType !== undefined) {
return " " + getDiagnosticText(option.paramType);
}
return "";
}
Expand Down
9 changes: 5 additions & 4 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1358,6 +1358,7 @@ module ts {
}

export interface CompilerOptions {
allowNonTsExtensions?: boolean;
charset?: string;
codepage?: number;
declaration?: boolean;
Expand All @@ -1375,14 +1376,14 @@ module ts {
noResolve?: boolean;
out?: string;
outDir?: string;
preserveConstEnums?: boolean;
removeComments?: boolean;
sourceMap?: boolean;
sourceRoot?: string;
suppressImplicitAnyIndexErrors?: boolean;
target?: ScriptTarget;
version?: boolean;
watch?: boolean;
preserveConstEnums?: boolean;
allowNonTsExtensions?: boolean;
[option: string]: string | number | boolean;
}

Expand Down Expand Up @@ -1419,7 +1420,7 @@ module ts {
type: string | Map<number>; // "string", "number", "boolean", or an object literal mapping named values to actual values
shortName?: string; // A short mnemonic for convenience - for instance, 'h' can be used in place of 'help'.
description?: DiagnosticMessage; // The message describing what the command line switch does
paramName?: DiagnosticMessage; // The name to be used for a non-boolean option's parameter.
paramType?: DiagnosticMessage; // The name to be used for a non-boolean option's parameter.
error?: DiagnosticMessage; // The error given when the argument does not fit a customized 'type'.
}

Expand Down Expand Up @@ -1557,7 +1558,7 @@ module ts {
tab = 0x09, // \t
verticalTab = 0x0B, // \v
}

export interface CancellationToken {
isCancellationRequested(): boolean;
}
Expand Down
7 changes: 6 additions & 1 deletion src/harness/harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,10 @@ module Harness {
options.preserveConstEnums = setting.value === 'true';
break;

case 'suppressimplicitanyindexerrors':
options.suppressImplicitAnyIndexErrors = setting.value === 'true';
break;

case 'includebuiltfile':
inputFiles.push({ unitName: setting.value, content: IO.readFile(libFolder + setting.value)});
break;
Expand Down Expand Up @@ -1170,7 +1174,8 @@ module Harness {
var optionRegex = /^[\/]{2}\s*@(\w+)\s*:\s*(\S*)/gm; // multiple matches on multiple lines

// List of allowed metadata names
var fileMetadataNames = ["filename", "comments", "declaration", "module", "nolib", "sourcemap", "target", "out", "outdir", "noemitonerror", "noimplicitany", "noresolve", "newline", "newlines", "emitbom", "errortruncation", "usecasesensitivefilenames", "preserveconstenums", "includebuiltfile"];

var fileMetadataNames = ["filename", "comments", "declaration", "module", "nolib", "sourcemap", "target", "out", "outdir", "noemitonerror", "noimplicitany", "noresolve", "newline", "newlines", "emitbom", "errortruncation", "usecasesensitivefilenames", "preserveconstenums", "includebuiltfile", "suppressimplicitanyindexerrors"];

function extractCompilerSettings(content: string): CompilerSetting[] {

Expand Down
7 changes: 4 additions & 3 deletions tests/baselines/reference/APISample_node_compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -1094,6 +1094,7 @@ declare module "typescript" {
Message = 2,
}
interface CompilerOptions {
allowNonTsExtensions?: boolean;
charset?: string;
codepage?: number;
declaration?: boolean;
Expand All @@ -1111,14 +1112,14 @@ declare module "typescript" {
noResolve?: boolean;
out?: string;
outDir?: string;
preserveConstEnums?: boolean;
removeComments?: boolean;
sourceMap?: boolean;
sourceRoot?: string;
suppressImplicitAnyIndexErrors?: boolean;
target?: ScriptTarget;
version?: boolean;
watch?: boolean;
preserveConstEnums?: boolean;
allowNonTsExtensions?: boolean;
[option: string]: string | number | boolean;
}
const enum ModuleKind {
Expand Down Expand Up @@ -1146,7 +1147,7 @@ declare module "typescript" {
type: string | Map<number>;
shortName?: string;
description?: DiagnosticMessage;
paramName?: DiagnosticMessage;
paramType?: DiagnosticMessage;
error?: DiagnosticMessage;
}
const enum CharacterCodes {
Expand Down
19 changes: 11 additions & 8 deletions tests/baselines/reference/APISample_node_compile.types
Original file line number Diff line number Diff line change
Expand Up @@ -3483,6 +3483,9 @@ declare module "typescript" {
interface CompilerOptions {
>CompilerOptions : CompilerOptions

allowNonTsExtensions?: boolean;
>allowNonTsExtensions : boolean

charset?: string;
>charset : string

Expand Down Expand Up @@ -3535,6 +3538,9 @@ declare module "typescript" {
outDir?: string;
>outDir : string

preserveConstEnums?: boolean;
>preserveConstEnums : boolean

removeComments?: boolean;
>removeComments : boolean

Expand All @@ -3544,6 +3550,9 @@ declare module "typescript" {
sourceRoot?: string;
>sourceRoot : string

suppressImplicitAnyIndexErrors?: boolean;
>suppressImplicitAnyIndexErrors : boolean

target?: ScriptTarget;
>target : ScriptTarget
>ScriptTarget : ScriptTarget
Expand All @@ -3554,12 +3563,6 @@ declare module "typescript" {
watch?: boolean;
>watch : boolean

preserveConstEnums?: boolean;
>preserveConstEnums : boolean

allowNonTsExtensions?: boolean;
>allowNonTsExtensions : boolean

[option: string]: string | number | boolean;
>option : string
}
Expand Down Expand Up @@ -3630,8 +3633,8 @@ declare module "typescript" {
>description : DiagnosticMessage
>DiagnosticMessage : DiagnosticMessage

paramName?: DiagnosticMessage;
>paramName : DiagnosticMessage
paramType?: DiagnosticMessage;
>paramType : DiagnosticMessage
>DiagnosticMessage : DiagnosticMessage

error?: DiagnosticMessage;
Expand Down
7 changes: 4 additions & 3 deletions tests/baselines/reference/APISample_standalone_compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -1092,6 +1092,7 @@ declare module ts {
Message = 2,
}
interface CompilerOptions {
allowNonTsExtensions?: boolean;
charset?: string;
codepage?: number;
declaration?: boolean;
Expand All @@ -1109,14 +1110,14 @@ declare module ts {
noResolve?: boolean;
out?: string;
outDir?: string;
preserveConstEnums?: boolean;
removeComments?: boolean;
sourceMap?: boolean;
sourceRoot?: string;
suppressImplicitAnyIndexErrors?: boolean;
target?: ScriptTarget;
version?: boolean;
watch?: boolean;
preserveConstEnums?: boolean;
allowNonTsExtensions?: boolean;
[option: string]: string | number | boolean;
}
const enum ModuleKind {
Expand Down Expand Up @@ -1144,7 +1145,7 @@ declare module ts {
type: string | Map<number>;
shortName?: string;
description?: DiagnosticMessage;
paramName?: DiagnosticMessage;
paramType?: DiagnosticMessage;
error?: DiagnosticMessage;
}
const enum CharacterCodes {
Expand Down
19 changes: 11 additions & 8 deletions tests/baselines/reference/APISample_standalone_compile.types
Original file line number Diff line number Diff line change
Expand Up @@ -3482,6 +3482,9 @@ declare module ts {
interface CompilerOptions {
>CompilerOptions : CompilerOptions

allowNonTsExtensions?: boolean;
>allowNonTsExtensions : boolean

charset?: string;
>charset : string

Expand Down Expand Up @@ -3534,6 +3537,9 @@ declare module ts {
outDir?: string;
>outDir : string

preserveConstEnums?: boolean;
>preserveConstEnums : boolean

removeComments?: boolean;
>removeComments : boolean

Expand All @@ -3543,6 +3549,9 @@ declare module ts {
sourceRoot?: string;
>sourceRoot : string

suppressImplicitAnyIndexErrors?: boolean;
>suppressImplicitAnyIndexErrors : boolean

target?: ScriptTarget;
>target : ScriptTarget
>ScriptTarget : ScriptTarget
Expand All @@ -3553,12 +3562,6 @@ declare module ts {
watch?: boolean;
>watch : boolean

preserveConstEnums?: boolean;
>preserveConstEnums : boolean

allowNonTsExtensions?: boolean;
>allowNonTsExtensions : boolean

[option: string]: string | number | boolean;
>option : string
}
Expand Down Expand Up @@ -3629,8 +3632,8 @@ declare module ts {
>description : DiagnosticMessage
>DiagnosticMessage : DiagnosticMessage

paramName?: DiagnosticMessage;
>paramName : DiagnosticMessage
paramType?: DiagnosticMessage;
>paramType : DiagnosticMessage
>DiagnosticMessage : DiagnosticMessage

error?: DiagnosticMessage;
Expand Down
Loading