I have a project with react typescript and I'm using prettier to format the code
In TS files I have some interfaces with Array<T>
and I would like to format to T[]
How can I do this?
This is outside the scope of Prettier, and more in the realm of eslint.
In fact @typescript-eslint/eslint-plugin
has a rule for this already named array-type
. See: https://typescript-eslint.io/rules/array-type/.
Which labels this as incorrect:
const x: Array<string> = ['a', 'b'];
const y: ReadonlyArray<string> = ['a', 'b'];
And this as correct:
const x: string[] = ['a', 'b'];
const y: readonly string[] = ['a', 'b'];