Skip to content

Object rest includes non-enumerable Symbols #29616

@planttheidea

Description

@planttheidea

TypeScript Version: 3.2.4

Search Terms: object rest, rest symbols

Code

// A *self-contained* demonstration of the problem follows...
// Test this by running `tsc` on the command-line, rather than through another build tool such as Gulp, Webpack, etc.

const object = { visible: true };

Object.defineProperty(object, 'does not appear', {
  enumerable: false,
  value: 'hidden key',
});

Object.defineProperty(object, Symbol('appears on rest'), {
  enumerable: false,
  value: 'hidden symbol',
});

// does not include non-enumerable symbol or key
console.log({ ...object });

const { visible, ...rest } = object;

// includes non-enumerable symbol, but excludes key
console.log(rest);

Expected behavior:

Non-enumerable symbols are not include in Object rest operations.

Actual behavior:

Non-enumerable symbols are included in Object rest operations.

Playground Link:

Playground

Related Issues:

I believe this was introduced with this PR => #12248.

This included Symbols in rest, but uses Object.getOwnPropertySymbols without using Object.prototype.propertyIsEnumerable check in the loops. You can see this in the generated output in the playground above.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: JS EmitThe issue relates to the emission of JavaScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions