Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Object Spread should not be preferred when the argument is this. #3117

Closed
snood1205 opened this issue Aug 11, 2017 · 5 comments
Closed

Object Spread should not be preferred when the argument is this. #3117

snood1205 opened this issue Aug 11, 2017 · 5 comments

Comments

@snood1205
Copy link

Bug Report

  • TSLint version: 5.5.0
  • TypeScript version: 2.3.3
  • Running TSLint via: WebStorm

TypeScript code being linted

const form = Object.assign({}, this);

with tslint.json configuration:

{
    "prefer-object-spread": true
}

Actual behavior

TSLint gives me the message

Use the object spread operator instead. (prefer-object-spread)

Expected behavior

TSLint should be ok with this usage of Object.assign({}, this) because per TS2698, "spread types may only be created from object types."

Somewhat related to this is: #2824

@ajafff
Copy link
Contributor

ajafff commented Aug 11, 2017

Have you already searched for or opened a corresponding issue in the typescript repo?
I think this is better fixed in the typescript compiler if they consider this a bug. Otherwise we can add an exception for this case to the rules.

@snood1205
Copy link
Author

snood1205 commented Aug 11, 2017

@ajafff The related TS issues are #10727 and #12756. It seems from the latter that people want support for this but it doesn't really seem to have been fixed thus far at least? I'm not sure if it ever will be fixed.

@ajafff
Copy link
Contributor

ajafff commented Aug 13, 2017

The linked PR that adds spread types to typescript looks abandoned. It's reasonable to add an exception to the rule until the compiler supports it.

@ajafff
Copy link
Contributor

ajafff commented Aug 15, 2017

Fixed by #3126

@ajafff ajafff closed this as completed Aug 15, 2017
@snood1205
Copy link
Author

@ajafff Awesome, thank you!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants