Skip to content

Commit 31a3352

Browse files
committed
Reorder visitType check to fix bug
1 parent 225fbb3 commit 31a3352

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

src/transform-inline/visitor-type-check.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -694,9 +694,7 @@ function visitIndexedAccessType(type: ts.IndexedAccessType, visitorContext: Visi
694694
}
695695

696696
export function visitType(type: ts.Type, visitorContext: VisitorContext): string {
697-
if (type.aliasTypeArguments && visitorContext.previousTypeReference !== type && (type as ts.TypeReference).target) {
698-
return visitTypeAliasReference(type as ts.TypeReference, visitorContext);
699-
} else if ((ts.TypeFlags.Any & type.flags) !== 0) {
697+
if ((ts.TypeFlags.Any & type.flags) !== 0) {
700698
// Any
701699
return visitAny(visitorContext);
702700
} else if ((ts.TypeFlags.Unknown & type.flags) !== 0) {
@@ -729,6 +727,8 @@ export function visitType(type: ts.Type, visitorContext: VisitorContext): string
729727
} else if (tsutils.isTypeReference(type) && visitorContext.previousTypeReference !== type) {
730728
// Type references.
731729
return visitTypeReference(type, visitorContext);
730+
} else if (type.aliasTypeArguments && visitorContext.previousTypeReference !== type && (type as ts.TypeReference).target) {
731+
return visitTypeAliasReference(type as ts.TypeReference, visitorContext);
732732
} else if ((ts.TypeFlags.TypeParameter & type.flags) !== 0) {
733733
// Type parameter
734734
return visitTypeParameter(type, visitorContext);

test/issue-88.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import * as assert from 'assert';
2+
import { is } from '../index';
3+
4+
/* https://github.com/woutervh-/typescript-is/issues/88 */
5+
6+
interface Z<T> {
7+
field: T;
8+
}
9+
10+
type Y<T> = Z<T>
11+
12+
type X = Y<string>
13+
14+
describe('is', () => {
15+
describe('Parameterised type alias of a parameterised type alias of an interface', () => {
16+
it('should return true for object with field type string', () => {
17+
assert.deepStrictEqual(is<X>({ field: 'some-string' }), true);
18+
});
19+
it('should return false for object with field type number', () => {
20+
assert.deepStrictEqual(is<X>({ field: 0 }), false);
21+
});
22+
it('should return false for object without field', () => {
23+
assert.deepStrictEqual(is<X>({}), false);
24+
});
25+
});
26+
});

0 commit comments

Comments
 (0)