Skip to content

__spreadArrays throws 'Cannot read property 'length' of null' when --strictNullChecks is off #33549

Closed
@KirillMetrik

Description

@KirillMetrik

TypeScript Version: 3.6.3

Search Terms:
__spreadArrays, 3.6.3

Code
Make sure to run with --strictNullChecks off and compile for ES5!

function foo(b: number[]=null){
    const a=[1,2,...b];
    console.log(a);
}

foo();

Expected behavior:
No error should be produced by this code.

Actual behavior:

VM690:3 Uncaught TypeError: Cannot read property 'length' of null
    at __spreadArrays (eval at <anonymous> (main-0.js:1018), <anonymous>:3:82)
    at foo (eval at <anonymous> (main-0.js:1018), <anonymous>:11:13)
    at eval (eval at <anonymous> (main-0.js:1018), <anonymous>:14:1)
    at main-0.js:1018

Playground Link:
Error thrown in TS 3.6.3:
https://www.typescriptlang.org/play/?strictNullChecks=false&target=1#code/FAMwrgdgxgLglgewgAhAhAKARgLmRMAWywFMAnAbQF0BeAgG3oEoBvYZD5KJAZxmQCGNCgEYANACYxAOllYqAbnaduEHgnolp9BAHMMApkoC+wUOgxGgA

No error is thrown in TS 3.5.1:
https://www.typescriptlang.org/play/?strictNullChecks=false&target=1&ts=3.5.1#code/FAMwrgdgxgLglgewgAhAhAKARgLmRMAWywFMAnAbQF0BeAgG3oEoBvYZD5KJAZxmQCGNCgEYANACYxAOllYqAbnaduEHgnolp9BAHMMApkoC+wUOgxGgA

Related Issues:
none
The problem was probably introduced by this pull request: #31166

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions