Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ESLint rule for spaces in union types in TypeScript

Is there an ESLint rule for TypeScript that allows enforcing using space in the following situation?

// good
let a: string | number = 4;

// bad
let a: string|number = 4;

The only stuff that might be helpful are type-annotation-spacing and space-infix-ops rules but they do not seem to work with union types.

like image 265
szczepaniakdominik Avatar asked Sep 08 '20 15:09

szczepaniakdominik


2 Answers

Seems the rule @typescript-eslint/space-infix-ops has been recently (May 2021) updated to handle this.

https://github.com/typescript-eslint/typescript-eslint/issues/51 (Not sure why the issue is still open)

like image 101
Xiromoreira Avatar answered Oct 22 '22 07:10

Xiromoreira


Maybe not what you want, but won't eslint-plugin-prettier do this for you?

like image 27
David Bradshaw Avatar answered Oct 22 '22 06:10

David Bradshaw