Skip to content

Commit 0e884c7

Browse files
authored
fix(eslint-plugin): [consistent-generic-constructors] resolve conflict with isolatedDeclarations if enabled in constructor option (typescript-eslint#11351)
* test: add tc * fix: ignore constructor report when id is enabled
1 parent 3f58afe commit 0e884c7

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

packages/eslint-plugin/src/rules/consistent-generic-constructors.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ export default createRule<Options, MessageIds>({
123123
return;
124124
}
125125

126-
if (lhs?.typeArguments && !rhs.typeArguments) {
126+
const isolatedDeclarations = context.parserOptions.isolatedDeclarations;
127+
if (!isolatedDeclarations && lhs?.typeArguments && !rhs.typeArguments) {
127128
const hasParens =
128129
context.sourceCode.getTokenAfter(rhs.callee)?.value === '(';
129130
const extraComments = new Set(

packages/eslint-plugin/tests/rules/consistent-generic-constructors.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ class A {
4545
`
4646
const a = function (a: Foo = new Foo<string>()) {};
4747
`,
48+
{
49+
code: `
50+
const foo: Foo<string> = new Foo();
51+
`,
52+
languageOptions: {
53+
parserOptions: {
54+
isolatedDeclarations: true,
55+
},
56+
},
57+
},
4858
// type-annotation
4959
{
5060
code: 'const a = new Foo();',

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy