Skip to content

Enhancement: [array-type] <Option to only enforce array style for simple types> #6952

Closed as not planned
@tylerlaprade

Description

@tylerlaprade

Before You File a Proposal Please Confirm You Have Done The Following...

My proposal is suitable for this project

  • I believe my proposal would be useful to the broader TypeScript community (meaning it is not a niche proposal).

Link to the rule's documentation

https://typescript-eslint.io/rules/array-type/

Description

A 4th option for the two property objects that would enforce array for simple types and not enforce either syntax for other types. I like always using the clean [] syntax for simple types, but it's situational whether Array<> is merited for more complex types - am I nesting multiple levels of array? Is it being used as a generic that already has lots of nested <>?

Fail

const x: Array<string> = ['a', 'b'];
const y: ReadonlyArray<string> = ['a', 'b'];
const z: Array<MyType> = ['a', 'b'];

Pass

const x: string[] = ['a', 'b'];
const y: readonly string[] = ['a', 'b'];
const z: MyType[] = ['a', 'b'];
const a: (string | number)[] = ['a', 'b'];
const b: { prop: string }[] = [{ prop: 'a' }];
const c: (() => void)[] = [() => {}];
const d: Array<string | number> = ['a', 'b'];
const e: Array<{ prop: string }> = [{ prop: 'a' }];
const f: Array<() => void> = [() => {}];

Additional Info

I suggest the name array-simple-flex, but any name is fine!

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement: plugin rule optionNew rule option for an existing eslint-plugin rulepackage: eslint-pluginIssues related to @typescript-eslint/eslint-pluginwontfixThis will not be worked on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy