Skip to content

Spread '...' should throw TypeError for 'undefined' #14362

Closed
@DLehenbauer

Description

@DLehenbauer

TypeScript Version: 2.1.1 / nightly (2.2.0-dev.201xxxxx)

Code

const a = [];
const x: number[] | undefined = undefined;

a.push(...x);

Expected behavior:
Always throws 'TypeError: x is not iterable', regardless of the '--target'.

Actual behavior:
For '--target es5', no error is thrown. This is because the spread is transformed into a call to '.apply()', which accepts 'undefined'.

(I stumbled on this when compiling tsc with '--target es2015', which revealed that the compiler had a minor dependency on the noncompliant spread behavior.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions