Skip to content

Type checker incorrectly refuses object spread of null or undefined #12460

Closed
@Jessidhia

Description

@Jessidhia

TypeScript Version: 2.2.0-dev.20161122

With --strictNullChecks.

Code

function spread(arg?: {}): {} {
  return {...arg}
}
spread()

Expected behavior:

spread() returns empty object {}.

Actual behavior:

Spread types may only be created from object types.


The spec specifically allows null and undefined spread arguments by having an early check before the ToObject abstract operation (3.1.2).

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptFixedA PR has been merged for this issue

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions