Skip to content

Commit

Permalink
fix(type-utils): checking of type aliases' type names by `typeMatches…
Browse files Browse the repository at this point in the history
…Specifier` (#6820)

* fix(specifierNameMatches): check aliasSymbol if it exists

* test: type aliases
  • Loading branch information
RebeccaStevens committed Apr 2, 2023
1 parent 79de27d commit 7ca2c90
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 22 deletions.
2 changes: 1 addition & 1 deletion packages/type-utils/src/TypeOrValueSpecifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ function specifierNameMatches(type: ts.Type, name: string | string[]): boolean {
if (typeof name === 'string') {
name = [name];
}
const symbol = type.getSymbol();
const symbol = type.aliasSymbol ?? type.getSymbol();
if (symbol === undefined) {
return false;
}
Expand Down
56 changes: 35 additions & 21 deletions packages/type-utils/tests/TypeOrValueSpecifier.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,28 +176,42 @@ describe('TypeOrValueSpecifier', () => {
runTestNegative,
);

it.each<[string, TypeOrValueSpecifier]>([
it.each<[string, TypeOrValueSpecifier]>(
[
'interface Foo {prop: string}; type Test = Foo;',
{ from: 'file', name: 'Foo' },
],
[
'interface Foo {prop: string}; type Test = Foo;',
{ from: 'file', name: ['Foo', 'Bar'] },
],
[
'interface Foo {prop: string}; type Test = Foo;',
{ from: 'file', name: 'Foo', path: 'tests/fixtures/file.ts' },
],
[
'interface Foo {prop: string}; type Test = Foo;',
{
from: 'file',
name: ['Foo', 'Bar'],
path: 'tests/fixtures/file.ts',
},
],
])('matches a matching file specifier: %s', runTestPositive);
[
'interface Foo {prop: string}; type Test = Foo;',
'type Foo = {prop: string}; type Test = Foo;',
].map((test): [string, TypeOrValueSpecifier] => [
test,
{ from: 'file', name: 'Foo' },
]),
[
'interface Foo {prop: string}; type Test = Foo;',
'type Foo = {prop: string}; type Test = Foo;',
].map((test): [string, TypeOrValueSpecifier] => [
test,
{ from: 'file', name: ['Foo', 'Bar'] },
]),
[
'interface Foo {prop: string}; type Test = Foo;',
'type Foo = {prop: string}; type Test = Foo;',
].map((test): [string, TypeOrValueSpecifier] => [
test,
{ from: 'file', name: 'Foo', path: 'tests/fixtures/file.ts' },
]),
[
'interface Foo {prop: string}; type Test = Foo;',
'type Foo = {prop: string}; type Test = Foo;',
].map((test): [string, TypeOrValueSpecifier] => [
test,
{
from: 'file',
name: ['Foo', 'Bar'],
path: 'tests/fixtures/file.ts',
},
]),
].flat(),
)('matches a matching file specifier: %s', runTestPositive);

it.each<[string, TypeOrValueSpecifier]>([
[
Expand Down

0 comments on commit 7ca2c90

Please sign in to comment.