Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7ca2c90

Browse files
fix(type-utils): checking of type aliases' type names by typeMatchesSpecifier (typescript-eslint#6820)
* fix(specifierNameMatches): check aliasSymbol if it exists * test: type aliases
1 parent 79de27d commit 7ca2c90

File tree

2 files changed

+36
-22
lines changed

2 files changed

+36
-22
lines changed

packages/type-utils/src/TypeOrValueSpecifier.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ function specifierNameMatches(type: ts.Type, name: string | string[]): boolean {
120120
if (typeof name === 'string') {
121121
name = [name];
122122
}
123-
const symbol = type.getSymbol();
123+
const symbol = type.aliasSymbol ?? type.getSymbol();
124124
if (symbol === undefined) {
125125
return false;
126126
}

packages/type-utils/tests/TypeOrValueSpecifier.test.ts

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -176,28 +176,42 @@ describe('TypeOrValueSpecifier', () => {
176176
runTestNegative,
177177
);
178178

179-
it.each<[string, TypeOrValueSpecifier]>([
179+
it.each<[string, TypeOrValueSpecifier]>(
180180
[
181-
'interface Foo {prop: string}; type Test = Foo;',
182-
{ from: 'file', name: 'Foo' },
183-
],
184-
[
185-
'interface Foo {prop: string}; type Test = Foo;',
186-
{ from: 'file', name: ['Foo', 'Bar'] },
187-
],
188-
[
189-
'interface Foo {prop: string}; type Test = Foo;',
190-
{ from: 'file', name: 'Foo', path: 'tests/fixtures/file.ts' },
191-
],
192-
[
193-
'interface Foo {prop: string}; type Test = Foo;',
194-
{
195-
from: 'file',
196-
name: ['Foo', 'Bar'],
197-
path: 'tests/fixtures/file.ts',
198-
},
199-
],
200-
])('matches a matching file specifier: %s', runTestPositive);
181+
[
182+
'interface Foo {prop: string}; type Test = Foo;',
183+
'type Foo = {prop: string}; type Test = Foo;',
184+
].map((test): [string, TypeOrValueSpecifier] => [
185+
test,
186+
{ from: 'file', name: 'Foo' },
187+
]),
188+
[
189+
'interface Foo {prop: string}; type Test = Foo;',
190+
'type Foo = {prop: string}; type Test = Foo;',
191+
].map((test): [string, TypeOrValueSpecifier] => [
192+
test,
193+
{ from: 'file', name: ['Foo', 'Bar'] },
194+
]),
195+
[
196+
'interface Foo {prop: string}; type Test = Foo;',
197+
'type Foo = {prop: string}; type Test = Foo;',
198+
].map((test): [string, TypeOrValueSpecifier] => [
199+
test,
200+
{ from: 'file', name: 'Foo', path: 'tests/fixtures/file.ts' },
201+
]),
202+
[
203+
'interface Foo {prop: string}; type Test = Foo;',
204+
'type Foo = {prop: string}; type Test = Foo;',
205+
].map((test): [string, TypeOrValueSpecifier] => [
206+
test,
207+
{
208+
from: 'file',
209+
name: ['Foo', 'Bar'],
210+
path: 'tests/fixtures/file.ts',
211+
},
212+
]),
213+
].flat(),
214+
)('matches a matching file specifier: %s', runTestPositive);
201215

202216
it.each<[string, TypeOrValueSpecifier]>([
203217
[

0 commit comments

Comments
 (0)