Description
Repro
TypeScript allows two different declarations to use the same name; they get merged into a single type. Besides a small handful of useful scenarios (e.g. namespace
+enum
), merged declarations generally arise as hacks in advanced abstractions (e.g. mixins) or retrofitted types for a legacy API. To avoid these complexities, I'll give somewhat contrived examples below.
The problem is that @typescript-eslint/naming-convention
seems to check each declaration independently, whereas merged declarations must all have the same name. As a result, ESLint may reject every possible name.
{
"rules": {
"@typescript-eslint/naming-convention": ["error"]
}
}
A couple example inputs:
export class SomeClass {}
// ('typeLike' must have 'PascalCase')
export type Example = SomeClass;
// ERROR: Variable name `Example` must match one of
// the following formats: camelCase, UPPER_CASE
export const Example = SomeClass;
// ('typeLike' must have 'PascalCase')
export interface Example2 {
x: boolean;
}
// ERROR: Function name `Example2` must match one of the following formats: camelCase
export function Example2(): Example2 {
return { x: false };
}
Expected Result
Here's a better way to handle merged declarations: The @typescript-eslint/naming-convention
rule should recognize merged declarations, and accept ANY applicable pattern, instead of applying ALL patterns.
For the sample declaration Example2
above, ESLint could accept EITHER 'PascalCase' OR 'camelCase' (whereas currently it requires BOTH).
Versions
package | version |
---|---|
@typescript-eslint/eslint-plugin |
3.3.0 |
@typescript-eslint/parser |
3.3.0 |
TypeScript |
3.5.3 |
ESLint |
7.2.0 |
node |
12.17.0 |
npm |
6.14.4 |