Skip to content

Array.prototype[Symbol.unscopables] is not a function #34610

Description

TypeScript Version: 3.7.0-dev.20191018

Search Terms:

  • Array
  • @@unscopables

Code

const x = [][Symbol.unscopables];
console.log(x.copyWithin);

const y = [][Symbol.unscopables]();
console.log(y.copyWithin);

Expected behavior:
x.copyWithin occurs no error, and [][Symbol.unscopables]() occurs type error.

Actual behavior:
x.copyWithin occurs type error, and [][Symbol.unscopables]() occurs runtime exception.

Playground Link:
http://www.typescriptlang.org/play/?ts=Nightly&ssl=6&ssc=1&pln=1&pc=1#code/MYewdgzgLgBAHjAvDA2gXRQZQJ4FsBGIANgHQCukoADgIb5ECmEaA3ALABQokxDJRIAOYAKOCWrYA6gEsoAC2lgAlOw6du0GNiSoMOAsXKUQtekzTCV68BF78hw7OJNTZC5aqA

Related Issues:

Activity

  1. NicholasLYang commented on Oct 22, 2019

    @NicholasLYang
    Contributor

    Is this because [Symbol.unscopables] is not a function but marked as one in the lib declaration file? According to MDN, object[Symbol.unscopables] should be an object. I removed the parens on this line and it appeared to fix the problem.

    Building works correctly with the change but my IDE complains: TS2717: Subsequent property declarations must have the same type. I'm not really sure where the other property declarations of Symbol.unscopables are. Could I get a point in the right direction? Also should I change all the tests that use [Symbol.unscopables]() to [Symbol.unscopables]?

  2. ExE-Boss commented on Jan 31, 2021

    @ExE-Boss
    Contributor

    Ron Buckton (@rbuckton) This is still broken, so I’m fixing it in #42566.

  3. locked as resolved and limited conversation to collaborators on Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugA bug in TypeScriptDomain: lib.d.tsThe issue relates to the different libraries shipped with TypeScript

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions