Skip to content
Draft
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
23 changes: 5 additions & 18 deletions internal/checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -5910,17 +5910,10 @@ func (c *Checker) getIteratedTypeOrElementType(use IterationUse, inputType *Type
}
return nil
}
// TODO: remove ScriptTargetES2015
iterableExists := c.getGlobalIterableType() != c.emptyGenericType
uplevelIteration := c.languageVersion >= core.ScriptTargetES2015 && iterableExists
downlevelIteration := !uplevelIteration && c.compilerOptions.DownlevelIteration == core.TSTrue
possibleOutOfBounds := c.compilerOptions.NoUncheckedIndexedAccess == core.TSTrue && use&IterationUsePossiblyOutOfBounds != 0
// Get the iterated type of an `Iterable<T>` or `IterableIterator<T>` only in ES2015
// or higher, when inside of an async generator or for-await-if, or when
// downlevelIteration is requested.
if uplevelIteration || downlevelIteration || allowAsyncIterables {
// We only report errors for an invalid iterable type in ES2015 or higher.
iterationTypes := c.getIterationTypesOfIterable(inputType, use, core.IfElse(uplevelIteration, errorNode, nil))
if iterableExists || allowAsyncIterables {
iterationTypes := c.getIterationTypesOfIterable(inputType, use, core.IfElse(iterableExists, errorNode, nil))
if checkAssignability {
if iterationTypes.nextType != nil {
var diagnostic *diagnostics.Message
Expand All @@ -5939,7 +5932,7 @@ func (c *Checker) getIteratedTypeOrElementType(use IterationUse, inputType *Type
}
}
}
if iterationTypes.yieldType != nil || uplevelIteration {
if iterationTypes.yieldType != nil || iterableExists {
if iterationTypes.yieldType == nil {
return nil
}
Expand Down Expand Up @@ -5988,7 +5981,7 @@ func (c *Checker) getIteratedTypeOrElementType(use IterationUse, inputType *Type
// number and string input is allowed, we want to say that number is not an
// array type or a string type.
allowsStrings := use&IterationUseAllowsStringInputFlag != 0 && !hasStringConstituent
defaultDiagnostic, maybeMissingAwait := c.getIterationDiagnosticDetails(use, inputType, allowsStrings, downlevelIteration)
defaultDiagnostic, maybeMissingAwait := c.getIterationDiagnosticDetails(use, inputType, allowsStrings)
c.errorAndMaybeSuggestAwait(errorNode, maybeMissingAwait && c.getAwaitedTypeOfPromise(arrayType) != nil, defaultDiagnostic, c.TypeToString(arrayType))
}
if hasStringConstituent {
Expand Down Expand Up @@ -6490,13 +6483,7 @@ func (c *Checker) reportTypeNotIterableError(errorNode *ast.Node, t *Type, allow
return c.errorAndMaybeSuggestAwait(errorNode, suggestAwait, message, c.TypeToString(t))
}

func (c *Checker) getIterationDiagnosticDetails(use IterationUse, inputType *Type, allowsStrings bool, downlevelIteration bool) (*diagnostics.Message, bool) {
if downlevelIteration {
if allowsStrings {
return diagnostics.Type_0_is_not_an_array_type_or_a_string_type_or_does_not_have_a_Symbol_iterator_method_that_returns_an_iterator, true
}
return diagnostics.Type_0_is_not_an_array_type_or_does_not_have_a_Symbol_iterator_method_that_returns_an_iterator, true
}
func (c *Checker) getIterationDiagnosticDetails(use IterationUse, inputType *Type, allowsStrings bool) (*diagnostics.Message, bool) {
yieldType := c.getIterationTypeOfIterable(use, IterationTypeKindYield, inputType, nil /*errorNode*/)
if yieldType != nil {
return diagnostics.Type_0_can_only_be_iterated_through_when_using_the_downlevelIteration_flag_or_with_a_target_of_es2015_or_higher, false
Expand Down
4 changes: 4 additions & 0 deletions internal/compiler/program.go
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,10 @@ func (p *Program) verifyCompilerOptions() {
createRemovedOptionDiagnostic("allowSyntheticDefaultImports", "false", "")
}

if !options.DownlevelIteration.IsUnknown() {
createRemovedOptionDiagnostic("downlevelIteration", "", "")
}

if options.StrictPropertyInitialization.IsTrue() && !options.GetStrictOptionValue(options.StrictNullChecks) {
createDiagnosticForOptionName(diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "strictPropertyInitialization", "strictNullChecks")
}
Expand Down
3 changes: 2 additions & 1 deletion internal/core/compileroptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ type CompilerOptions struct {
EmitDeclarationOnly Tristate `json:"emitDeclarationOnly,omitzero"`
EmitBOM Tristate `json:"emitBOM,omitzero"`
EmitDecoratorMetadata Tristate `json:"emitDecoratorMetadata,omitzero"`
DownlevelIteration Tristate `json:"downlevelIteration,omitzero"`
Declaration Tristate `json:"declaration,omitzero"`
DeclarationDir string `json:"declarationDir,omitzero"`
DeclarationMap Tristate `json:"declarationMap,omitzero"`
Expand Down Expand Up @@ -124,6 +123,8 @@ type CompilerOptions struct {
// Deprecated: Do not use outside of options parsing and validation.
BaseUrl string `json:"baseUrl,omitzero"`
// Deprecated: Do not use outside of options parsing and validation.
DownlevelIteration Tristate `json:"downlevelIteration,omitzero"`
// Deprecated: Do not use outside of options parsing and validation.
ESModuleInterop Tristate `json:"esModuleInterop,omitzero"`
// Deprecated: Do not use outside of options parsing and validation.
OutFile string `json:"outFile,omitzero"`
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error TS5102: Option 'downlevelIteration' has been removed. Please remove it from your configuration.


!!! error TS5102: Option 'downlevelIteration' has been removed. Please remove it from your configuration.
==== blockScopedBindingsInDownlevelGenerator.ts (0 errors) ====
function* a() {
for (const i of [1,2,3]) {
(() => i)()
yield i
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
-
-
-!!! error TS5101: Option 'downlevelIteration' is deprecated and will stop functioning in TypeScript 7.0. Specify compilerOption '"ignoreDeprecations": "6.0"' to silence this error.
-==== blockScopedBindingsInDownlevelGenerator.ts (0 errors) ====
- function* a() {
- for (const i of [1,2,3]) {
- (() => i)()
- yield i
- }
- }
+<no content>
+error TS5102: Option 'downlevelIteration' has been removed. Please remove it from your configuration.
+
+
+!!! error TS5102: Option 'downlevelIteration' has been removed. Please remove it from your configuration.
==== blockScopedBindingsInDownlevelGenerator.ts (0 errors) ====
function* a() {
for (const i of [1,2,3]) {
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error TS5102: Option 'downlevelIteration' has been removed. Please remove it from your configuration.


!!! error TS5102: Option 'downlevelIteration' has been removed. Please remove it from your configuration.
==== sourceMapValidationVarInDownLevelGenerator.ts (0 errors) ====
function * f() {
var x = 1, y;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
-
-
-!!! error TS5101: Option 'downlevelIteration' is deprecated and will stop functioning in TypeScript 7.0. Specify compilerOption '"ignoreDeprecations": "6.0"' to silence this error.
-==== sourceMapValidationVarInDownLevelGenerator.ts (0 errors) ====
- function * f() {
- var x = 1, y;
- }
+<no content>
+error TS5102: Option 'downlevelIteration' has been removed. Please remove it from your configuration.
+
+
+!!! error TS5102: Option 'downlevelIteration' has been removed. Please remove it from your configuration.
==== sourceMapValidationVarInDownLevelGenerator.ts (0 errors) ====
function * f() {
var x = 1, y;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error TS5102: Option 'downlevelIteration' has been removed. Please remove it from your configuration.


!!! error TS5102: Option 'downlevelIteration' has been removed. Please remove it from your configuration.
==== ES5For-of33.ts (0 errors) ====
for (var v of ['a', 'b', 'c']) {
console.log(v);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
-
-
-!!! error TS5101: Option 'downlevelIteration' is deprecated and will stop functioning in TypeScript 7.0. Specify compilerOption '"ignoreDeprecations": "6.0"' to silence this error.
-==== ES5For-of33.ts (0 errors) ====
- for (var v of ['a', 'b', 'c']) {
- console.log(v);
- }
+<no content>
+error TS5102: Option 'downlevelIteration' has been removed. Please remove it from your configuration.
+
+
+!!! error TS5102: Option 'downlevelIteration' has been removed. Please remove it from your configuration.
==== ES5For-of33.ts (0 errors) ====
for (var v of ['a', 'b', 'c']) {
console.log(v);
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
error TS5102: Option 'downlevelIteration' has been removed. Please remove it from your configuration.
ES5For-of34.ts(4,6): error TS2322: Type 'string' is not assignable to type 'number'.


!!! error TS5102: Option 'downlevelIteration' has been removed. Please remove it from your configuration.
==== ES5For-of34.ts (1 errors) ====
function foo() {
return { x: 0 };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
+++ new.ES5For-of34(target=es2015).errors.txt
@@= skipped -0, +0 lines =@@
-error TS5101: Option 'downlevelIteration' is deprecated and will stop functioning in TypeScript 7.0. Specify compilerOption '"ignoreDeprecations": "6.0"' to silence this error.
+error TS5102: Option 'downlevelIteration' has been removed. Please remove it from your configuration.
ES5For-of34.ts(4,6): error TS2322: Type 'string' is not assignable to type 'number'.


-!!! error TS5101: Option 'downlevelIteration' is deprecated and will stop functioning in TypeScript 7.0. Specify compilerOption '"ignoreDeprecations": "6.0"' to silence this error.
+!!! error TS5102: Option 'downlevelIteration' has been removed. Please remove it from your configuration.
==== ES5For-of34.ts (1 errors) ====
function foo() {
return { x: 0 };
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
error TS5102: Option 'downlevelIteration' has been removed. Please remove it from your configuration.
ES5For-of35.ts(1,13): error TS2339: Property 'x' does not exist on type 'Number'.
ES5For-of35.ts(1,23): error TS2339: Property 'y' does not exist on type 'Number'.


!!! error TS5102: Option 'downlevelIteration' has been removed. Please remove it from your configuration.
==== ES5For-of35.ts (2 errors) ====
for (const {x: a = 0, y: b = 1} of [2, 3]) {
~
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
+++ new.ES5For-of35(target=es2015).errors.txt
@@= skipped -0, +0 lines =@@
-error TS5101: Option 'downlevelIteration' is deprecated and will stop functioning in TypeScript 7.0. Specify compilerOption '"ignoreDeprecations": "6.0"' to silence this error.
+error TS5102: Option 'downlevelIteration' has been removed. Please remove it from your configuration.
ES5For-of35.ts(1,13): error TS2339: Property 'x' does not exist on type 'Number'.
ES5For-of35.ts(1,23): error TS2339: Property 'y' does not exist on type 'Number'.


-!!! error TS5101: Option 'downlevelIteration' is deprecated and will stop functioning in TypeScript 7.0. Specify compilerOption '"ignoreDeprecations": "6.0"' to silence this error.
+!!! error TS5102: Option 'downlevelIteration' has been removed. Please remove it from your configuration.
==== ES5For-of35.ts (2 errors) ====
for (const {x: a = 0, y: b = 1} of [2, 3]) {
~
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
error TS5102: Option 'downlevelIteration' has been removed. Please remove it from your configuration.
ES5For-of36.ts(1,10): error TS2488: Type 'number' must have a '[Symbol.iterator]()' method that returns an iterator.


!!! error TS5102: Option 'downlevelIteration' has been removed. Please remove it from your configuration.
==== ES5For-of36.ts (1 errors) ====
for (let [a = 0, b = 1] of [2, 3]) {
~~~~~~~~~~~~~~
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
+++ new.ES5For-of36(target=es2015).errors.txt
@@= skipped -0, +0 lines =@@
-error TS5101: Option 'downlevelIteration' is deprecated and will stop functioning in TypeScript 7.0. Specify compilerOption '"ignoreDeprecations": "6.0"' to silence this error.
+error TS5102: Option 'downlevelIteration' has been removed. Please remove it from your configuration.
ES5For-of36.ts(1,10): error TS2488: Type 'number' must have a '[Symbol.iterator]()' method that returns an iterator.


-!!! error TS5101: Option 'downlevelIteration' is deprecated and will stop functioning in TypeScript 7.0. Specify compilerOption '"ignoreDeprecations": "6.0"' to silence this error.
+!!! error TS5102: Option 'downlevelIteration' has been removed. Please remove it from your configuration.
==== ES5For-of36.ts (1 errors) ====
for (let [a = 0, b = 1] of [2, 3]) {
~~~~~~~~~~~~~~
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
error TS5102: Option 'downlevelIteration' has been removed. Please remove it from your configuration.


!!! error TS5102: Option 'downlevelIteration' has been removed. Please remove it from your configuration.
==== ES5For-of37.ts (0 errors) ====
// https://github.com/microsoft/TypeScript/issues/30083

for (const i of [0, 1, 2, 3, 4]) {
try {
// Ensure catch binding for the following loop is reset per iteration:
for (const j of [1, 2, 3]) {
if (i === 2) {
throw new Error('ERR');
}
}
console.log(i);
} catch (err) {
console.log('E %s %s', i, err);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,10 @@
-
-
-!!! error TS5101: Option 'downlevelIteration' is deprecated and will stop functioning in TypeScript 7.0. Specify compilerOption '"ignoreDeprecations": "6.0"' to silence this error.
-==== ES5For-of37.ts (0 errors) ====
- // https://github.com/microsoft/TypeScript/issues/30083
-
- for (const i of [0, 1, 2, 3, 4]) {
- try {
- // Ensure catch binding for the following loop is reset per iteration:
- for (const j of [1, 2, 3]) {
- if (i === 2) {
- throw new Error('ERR');
- }
- }
- console.log(i);
- } catch (err) {
- console.log('E %s %s', i, err);
- }
- }
+<no content>
+error TS5102: Option 'downlevelIteration' has been removed. Please remove it from your configuration.
+
+
+!!! error TS5102: Option 'downlevelIteration' has been removed. Please remove it from your configuration.
==== ES5For-of37.ts (0 errors) ====
// https://github.com/microsoft/TypeScript/issues/30083

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
error TS5102: Option 'downlevelIteration' has been removed. Please remove it from your configuration.


!!! error TS5102: Option 'downlevelIteration' has been removed. Please remove it from your configuration.
==== arrayLiteralSpreadES5iterable.ts (0 errors) ====
function f0() {
var a = [1, 2, 3];
var a1 = [...a];
var a2 = [1, ...a];
var a3 = [1, 2, ...a];
var a4 = [...a, 1];
var a5 = [...a, 1, 2];
var a6 = [1, 2, ...a, 1, 2];
var a7 = [1, ...a, 2, ...a];
var a8 = [...a, ...a, ...a];
}

function f1() {
var a = [1, 2, 3];
var b = ["hello", ...a, true];
var b: (string | number | boolean)[];
}

function f2() {
var a = [...[...[...[...[...[]]]]]];
var b = [...[...[...[...[...[5]]]]]];
}

Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,10 @@
-
-
-!!! error TS5101: Option 'downlevelIteration' is deprecated and will stop functioning in TypeScript 7.0. Specify compilerOption '"ignoreDeprecations": "6.0"' to silence this error.
-==== arrayLiteralSpreadES5iterable.ts (0 errors) ====
- function f0() {
- var a = [1, 2, 3];
- var a1 = [...a];
- var a2 = [1, ...a];
- var a3 = [1, 2, ...a];
- var a4 = [...a, 1];
- var a5 = [...a, 1, 2];
- var a6 = [1, 2, ...a, 1, 2];
- var a7 = [1, ...a, 2, ...a];
- var a8 = [...a, ...a, ...a];
- }
-
- function f1() {
- var a = [1, 2, 3];
- var b = ["hello", ...a, true];
- var b: (string | number | boolean)[];
- }
-
- function f2() {
- var a = [...[...[...[...[...[]]]]]];
- var b = [...[...[...[...[...[5]]]]]];
- }
-
+<no content>
+error TS5102: Option 'downlevelIteration' has been removed. Please remove it from your configuration.
+
+
+!!! error TS5102: Option 'downlevelIteration' has been removed. Please remove it from your configuration.
==== arrayLiteralSpreadES5iterable.ts (0 errors) ====
function f0() {
var a = [1, 2, 3];
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
error TS5102: Option 'downlevelIteration' has been removed. Please remove it from your configuration.


!!! error TS5102: Option 'downlevelIteration' has been removed. Please remove it from your configuration.
==== asyncArrowFunction11_es5.ts (0 errors) ====
// https://github.com/Microsoft/TypeScript/issues/24722
class A {
b = async (...args: any[]) => {
await Promise.resolve();
const obj = { ["a"]: () => this }; // computed property name after `await` triggers case
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
-
-
-!!! error TS5101: Option 'downlevelIteration' is deprecated and will stop functioning in TypeScript 7.0. Specify compilerOption '"ignoreDeprecations": "6.0"' to silence this error.
-==== asyncArrowFunction11_es5.ts (0 errors) ====
- // https://github.com/Microsoft/TypeScript/issues/24722
- class A {
- b = async (...args: any[]) => {
- await Promise.resolve();
- const obj = { ["a"]: () => this }; // computed property name after `await` triggers case
- };
- }
+<no content>
+error TS5102: Option 'downlevelIteration' has been removed. Please remove it from your configuration.
+
+
+!!! error TS5102: Option 'downlevelIteration' has been removed. Please remove it from your configuration.
==== asyncArrowFunction11_es5.ts (0 errors) ====
// https://github.com/Microsoft/TypeScript/issues/24722
class A {
Loading