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

Typescript errors: cannot read property 'length' of undefined for spread operator, incompatibility from 3.5.1 to 3.6.3 #38855

Closed
HarkaranGill opened this issue May 29, 2020 · 2 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@HarkaranGill
Copy link

HarkaranGill commented May 29, 2020

Upgraded TypeScript library to the latest recently. Found an incompatibility issue going from 3.5.1 to 3.6.3 .

https://www.typescriptlang.org/play/index.html?target=1#code/GYVwdgxgLglg9mABAGTgcwBQFMBuWxQAqAngA5YBciAzlAE4xhoA0iu+UAkgCJUCGYYqzB8AtpRr1GLRMDh0IWAGIAbENQAWiAPxUARnDgqsA1gDoLAayzEAanzVYACnxh1qVWgyYBtALoAlIhUOHAwACaIAN4AUIjxiBAI1EZYZiroGABEABJYKhmIAOryKuFZAQDcMQC+MTFJYLSIGWho0tx8UHz8gogAvIjg4VjAjFjh1aiYAOQAwiowEJYzrDM5TquIWdQmChpK8qJZrPQgWGtgcCMAcmJYWzt7EBpydMdrpHx0HDfXWHdxI8AMrPDQGAAeJ0QMwgi2WAH0oGQHms3qIthZ0uh2kxOt0qkA

Make sure Target is ES5.

For 3.6.3 and up we get :
Uncaught TypeError: Cannot read property 'length' of undefined
at __spreadArrays (tsWorker.js:21)
at eval (eval at (main-3.js:1239), :17:19)
at main-3.js:1239

For 3.5.1 and lower it passes without error.

SpreadArray function was introduced here, which triggers this exception: #31166

To be fair spread operator on undefined should fail! As undefined is not iterable.

Just reporting this issue for awareness, as originally did not check for undefined when using the spread operator as older versions of TypeScript did not catch this.

Not sure if this should be marked as a "bug"

@j-oliveras
Copy link
Contributor

To compare, running a simplified version of your code compiled to target esnext on Firefox and Node (both supporting spread operator):

function Log(...keyValuePairs: string[]) : void {
    console.log("Hello World");
}

const loggingData: any = undefined;
Log(...loggingData);

Playground
Firefox 76.0.1: TypeError: loggingData is undefined
Node 12.16.3: Uncaught TypeError: Log is not iterable (cannot read property Symbol(Symbol.iterator))

So typescript generated have a similar behavior as native support.

@RyanCavanaugh RyanCavanaugh added the Working as Intended The behavior described is the intended behavior; this is not a bug label Jun 11, 2020
@typescript-bot
Copy link
Collaborator

This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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

4 participants