Skip to content

Inconsitent (dis)allowing of undefined in spread operator #20153

@olekzabl

Description

@olekzabl

TypeScript Version: 2.7.0-dev.20171118

Code

declare let v1: undefined;
declare let v2: {[key: string]: string};
declare let v3: {[key: string]: string}|undefined;

let map: {[key: string]: string};
map = {...v1}; // FAILS
map = {...v2};
map = {...undefined}; // FAILS
map = {...v3}; // OK

Expected behavior:

  1. Consistency: undefined values are either allowed or disallowed in spread operator, regardless of whether they come explicitly, through a variable of undefined type, or through a variable of a variant type with an undefined branch.
  2. Ideally, backward compatibility with the previous versions.

Actual behavior:

  1. Values of "bare" undefined type are forbidden, while values of at least some X|undefined types
    are allowed.
  2. No backward compatibility, as the lines commented with "FAILS" are accepted by 2.5.3.

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