diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 9b75678ccb2b3..89161c9ab42c3 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -64,7 +64,8 @@ namespace ts { const noUnusedIdentifiers = !!compilerOptions.noUnusedLocals || !!compilerOptions.noUnusedParameters; const allowSyntheticDefaultImports = typeof compilerOptions.allowSyntheticDefaultImports !== "undefined" ? compilerOptions.allowSyntheticDefaultImports : modulekind === ModuleKind.System; const strictNullChecks = compilerOptions.strictNullChecks === undefined ? compilerOptions.strict : compilerOptions.strictNullChecks; - const granularConst = compilerOptions.granularConst; + const widenTypes = compilerOptions.widenTypes === undefined ? true : compilerOptions.widenTypes; + const granularConst = !widenTypes; const noImplicitAny = compilerOptions.noImplicitAny === undefined ? compilerOptions.strict : compilerOptions.noImplicitAny; const noImplicitThis = compilerOptions.noImplicitThis === undefined ? compilerOptions.strict : compilerOptions.noImplicitThis; diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 6a90b07e03e01..bff3e3c226029 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -270,11 +270,11 @@ namespace ts { description: Diagnostics.Enable_strict_null_checks }, { - name: "granularConst", + name: "widenTypes", type: "boolean", showInSimplifiedHelpView: true, category: Diagnostics.Strict_Type_Checking_Options, - description: Diagnostics.Enable_granular_type_inference_using_const + description: Diagnostics.Automatically_widen_types_even_in_params_and_const }, { name: "noImplicitThis", diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 2f75ad9cc8473..c036f753380d2 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -3302,7 +3302,7 @@ "category": "Message", "code": 6185 }, - "Enable granular type inference using `const`.": { + "Automatically widen types even in params and `const`.": { "category": "Message", "code": 6186 }, diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 34f2234271600..9959110c39ea7 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -3622,7 +3622,7 @@ namespace ts { sourceRoot?: string; strict?: boolean; strictNullChecks?: boolean; // Always combine with strict property - granularConst?: boolean; + widenTypes?: boolean; /* @internal */ stripInternal?: boolean; suppressExcessPropertyErrors?: boolean; suppressImplicitAnyIndexErrors?: boolean; diff --git a/src/harness/unittests/configurationExtension.ts b/src/harness/unittests/configurationExtension.ts index dfc523f62e6d9..6a894c61aeb84 100644 --- a/src/harness/unittests/configurationExtension.ts +++ b/src/harness/unittests/configurationExtension.ts @@ -16,10 +16,10 @@ namespace ts { strictNullChecks: false } }, - "/dev/tsconfig.granularconst.json": { + "/dev/tsconfig.widenTypes.json": { extends: "./tsconfig", compilerOptions: { - granularConst: true + widenTypes: false } }, "/dev/configs/base.json": { diff --git a/src/harness/unittests/transpile.ts b/src/harness/unittests/transpile.ts index 21cacbaae87bb..c76f398bb77bc 100644 --- a/src/harness/unittests/transpile.ts +++ b/src/harness/unittests/transpile.ts @@ -413,8 +413,8 @@ var x = 0;`, { options: { compilerOptions: { strictNullChecks: true }, fileName: "input.js", reportDiagnostics: true } }); - transpilesCorrectly("Supports setting 'granularConst'", "x;", { - options: { compilerOptions: { granularConst: true }, fileName: "input.js", reportDiagnostics: true } + transpilesCorrectly("Supports setting 'widenTypes'", "x;", { + options: { compilerOptions: { widenTypes: true }, fileName: "input.js", reportDiagnostics: true } }); transpilesCorrectly("Supports setting 'stripInternal'", "x;", { diff --git a/src/server/protocol.ts b/src/server/protocol.ts index 2188eca700c52..e4ccb8305b428 100644 --- a/src/server/protocol.ts +++ b/src/server/protocol.ts @@ -2448,7 +2448,7 @@ namespace ts.server.protocol { sourceRoot?: string; strict?: boolean; strictNullChecks?: boolean; - granularConst?: boolean; + widenTypes?: boolean; suppressExcessPropertyErrors?: boolean; suppressImplicitAnyIndexErrors?: boolean; target?: ScriptTarget | ts.ScriptTarget; diff --git a/tests/cases/compiler/dontWiden.ts b/tests/cases/compiler/dontWiden.ts index fb437c733a072..c6bd6e7484376 100644 --- a/tests/cases/compiler/dontWiden.ts +++ b/tests/cases/compiler/dontWiden.ts @@ -1,4 +1,4 @@ -// @granularConst: true +// @widenTypes: false const c = [1, 'a']; const d = { a: 1, b: 'c' };