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

Type must have a '[Symbol.iterator]()' method error for ...x where x: T[] with "target": "es2018". #22768

Closed
earshinov opened this issue Mar 21, 2018 · 5 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@earshinov
Copy link

TypeScript Version: 2.8.0-dev.20180321

Search Terms: Symbol.Iterator, compilerOptions, compilerOptions.lib, es6, es2018, default, lib

Code

(function() {
    var a = [4, 5, 6];
    var b = [1, 2, 3];
    a.push(...b);
})();

tsconfig.json:

{
    "compilerOptions": {
        "target": "es2018"
    }
}

Expected behavior:
No errors

Actual behavior:

src/index.ts(4,15): error TS2488: Type must have a '[Symbol.iterator]()' method that returns an iterator.

No errors when compiled with "target": "es6" in tsconfig.json

Playground Link:
The issue is not reproducible in the playground as it does not take a tsconfig.

Related Issues:
None as far as I know.

@earshinov
Copy link
Author

Presumably, the defaults for lib described on the Compiler Options page do not work for "es2018".

When I explicitly configure "lib": [ "dom", "es6", "dom.iterable", "scripthost" ] in tsconfig.json, the code compiles without any errors.

@mhegazy
Copy link
Contributor

mhegazy commented Mar 26, 2018

--target es2018 is not supported yet. it is tracked by #20463.

So the closest you can get to this is --target es2017 --lib es2018,dom,dom.iterable

@mhegazy mhegazy added the Working as Intended The behavior described is the intended behavior; this is not a bug label Mar 26, 2018
@earshinov
Copy link
Author

@mhegazy Thank you for the information. I guess this ticket should be left open in order to check if everything works when --es2018 support is complete.

@mhegazy
Copy link
Contributor

mhegazy commented Mar 28, 2018

We already have one issue tracking it in #20463. ideally we would keep one ticket per issue.

@earshinov
Copy link
Author

earshinov commented Mar 28, 2018

OK, closing then. For now we switched back to es6 instead of es2018.

@microsoft microsoft locked and limited conversation to collaborators Jul 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

2 participants