Skip to content

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

@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