Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mysticatea opened this issue Apr 21, 2018 · 2 comments
Closed

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

mysticatea opened this issue Apr 21, 2018 · 2 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@mysticatea
Copy link

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:

@mysticatea
Copy link
Author

mysticatea commented Apr 21, 2018

It resolved by !:

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

But I'd like to leave opening this issue because of the confusing error message.

@mhegazy mhegazy added the Working as Intended The behavior described is the intended behavior; this is not a bug label Apr 21, 2018
@typescript-bot
Copy link
Collaborator

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

@microsoft microsoft locked and limited conversation to collaborators Jul 31, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

3 participants