I am trying to get Typescript ESLint to detect when there is no space between the angle brackets when you want to set a type to a generic method/class. The main goal is to get warnings / errors if the spaces are missing. Automatic fixing is just a nice to have.
For example this is the incorrect code:
class MyGenricClass<T> {
MyGenericProperty: T;
MyHttpResponse: <HttpResponse<T>>;
}
const InstancedClass = new MyGenricClass<string>();
I want the the generic types to have spaces inside the angle brackets like the following:
class MyGenricClass< T > {
MyGenericProperty: T;
MyHttpResponse: < HttpResponse< T > >;
}
const InstancedClass = new MyGenricClass< string >();
I've checked the following which I could find in TypeScript-Eslint documentation:
- @typescript-eslint/func-call-spacing - just adds white space before the function call
- @typescript-eslint/type-annotation-spacing - Works for
let foo: string = "bar";but not for the angle brackets - @typescript-eslint/space-before-function-paren - Feels the same as func-call-spacing
I've also tried to google and duckduckgo, without any success. Searched that I've done are:
- typescript eslint space between generic
- typescript eslint generic spacing
- typescript eslint template spacing
- typescript eslint generic type spacing
- typescript eslint type annotation spacing
To be honest, I am not sure what's the correct naming for what I want to achieve. So I would appreciate some suggestions where I could look for a solution or a possible workaround. Worst case scenario is to write this rule myself, and create a PR to @typescript-eslint.
Many thanks in advance!