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

array-type vs prefer-array-literal #2946

Closed
dashmug opened this issue Jun 23, 2017 · 3 comments
Closed

array-type vs prefer-array-literal #2946

dashmug opened this issue Jun 23, 2017 · 3 comments
Labels

Comments

@dashmug
Copy link

dashmug commented Jun 23, 2017

Bug Report

  • TSLint version: 5.4.3
  • TypeScript version: 2.3.4
  • Running TSLint via: WebStorm

TypeScript code being linted

I want values to be a mixed array of either an object or a number.

// Violates 'array-type' rule
const values: (object | number)[] = []
// Violates 'prefer-array-literal' rule
const values: Array<object | number> = []

with tslint.json configuration:

{
  "extends": [
    "tslint:latest",
    "tslint-eslint-rules",
    "tslint-config-airbnb"
  ]
}

How can I write my code so I won't violate both rules? Are those two conflicting with each other and I have to give up one rule?

@adidahiya
Copy link
Contributor

adidahiya commented Jun 23, 2017

It seems like prefer-array-literal just isn't compatible with the default config for the array-type rule. That rule isn't maintained by tslint, it's part of tslint-microsoft-contrib. You could set the "array" option on array-type to get them to work together. You might want to file an issue on tslint-config-airbnb about this.

@iamakulov
Copy link

For everyone getting here from Google search, this can also be fixed without changing the array-type rule and reformatting array usages. Enable the allow-type-parameters option in prefer-array-literal:

{
  "rules": {
    "prefer-array-literal": [true, { "allow-type-parameters": true }]
  }
}

@JoshuaKGoldberg
Copy link
Contributor

Closing as external. Feel free to post an issue on tslint-microsoft-contrib!

yurloc added a commit to yurloc/optaweb-vehicle-routing that referenced this issue Dec 11, 2018
yurloc added a commit to yurloc/optaweb-vehicle-routing that referenced this issue Dec 11, 2018
yurloc added a commit to kiegroup/optaweb-vehicle-routing that referenced this issue Dec 11, 2018
* Install tslint-config-airbnb

* Remove tslint exclusion, add --project argument

* Remove extra parameters

* More script friendly

* IDEA fixes

* Ignore import names for now

* Rest of comma and semi fixes

* Manual fixes

* Sort rules

* Allow Array type parameters

palantir/tslint#2946 (comment)

* Allow pascal case variable names because of SFCs

Co-Authored-By: yurloc <jiri.locker@gmail.com>

* Allow pascal case because of components declared as fuctions
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants