Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
Description
Repro
TypeScript allows two different declarations to use the same name; they getmerged 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:
exportclassSomeClass{}// ('typeLike' must have 'PascalCase')exporttypeExample=SomeClass;// ERROR: Variable name `Example` must match one of// the following formats: camelCase, UPPER_CASEexportconstExample=SomeClass;
// ('typeLike' must have 'PascalCase')exportinterfaceExample2{x:boolean;}// ERROR: Function name `Example2` must match one of the following formats: camelCaseexportfunctionExample2():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 declarationExample2
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 |