Skip to content

The 2nd argument of Object.defineProperty cannot be a symbol #23603

Closed
@mysticatea

Description

@mysticatea

TypeScript Version: 2.9.0-dev.20180421 and 2.8.1

Search Terms: Object.defineProperty Symbol

Code

Object.defineProperty(
    Array.prototype,
    Symbol.iterator,
    Object.getOwnPropertyDescriptor(Array.prototype, "values"),
)

Expected behavior:

No compile errors.

Actual behavior:

error TS2345: Argument of type 'symbol' is not assignable to parameter of type 'string'.

Symbol.iterator,
~~~~~~~~~~~~~~~

I'm not sure why it is. PropertyKey looks to include symbol type.

Playground Link:

https://www.typescriptlang.org/play/index.html#src=Object.defineProperty(%0D%0A%20%20%20%20Array.prototype%2C%0D%0A%20%20%20%20Symbol.iterator%2C%0D%0A%20%20%20%20Object.getOwnPropertyDescriptor(Array.prototype%2C%20%22values%22)%2C%0D%0A)%0D%0A ※ enable strictNullChecks.

Related Issues:

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