Skip to content

Commit 9c300c2

Browse files
authored
Merge pull request #89 from davidfurey/issue-88-type-alias-2
Reorder visitType check to fix bug
2 parents 86bfdf7 + 31a3352 commit 9c300c2

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
@@ -1156,9 +1156,7 @@ function visitTemplateLiteralType(type: ts.TemplateLiteralType, visitorContext:
11561156
}
11571157

11581158
export function visitType(type: ts.Type, visitorContext: VisitorContext): string {
1159-
if (type.aliasTypeArguments && visitorContext.previousTypeReference !== type && (type as ts.TypeReference).target) {
1160-
return visitTypeAliasReference(type as ts.TypeReference, visitorContext);
1161-
} else if ((ts.TypeFlags.Any & type.flags) !== 0) {
1159+
if ((ts.TypeFlags.Any & type.flags) !== 0) {
11621160
// Any
11631161
return visitAny(visitorContext);
11641162
} else if ((ts.TypeFlags.Unknown & type.flags) !== 0) {
@@ -1191,6 +1189,8 @@ export function visitType(type: ts.Type, visitorContext: VisitorContext): string
11911189
} else if (tsutils.isTypeReference(type) && visitorContext.previousTypeReference !== type) {
11921190
// Type references.
11931191
return visitTypeReference(type, visitorContext);
1192+
} else if (type.aliasTypeArguments && visitorContext.previousTypeReference !== type && (type as ts.TypeReference).target) {
1193+
return visitTypeAliasReference(type as ts.TypeReference, visitorContext);
11941194
} else if ((ts.TypeFlags.TypeParameter & type.flags) !== 0) {
11951195
// Type parameter
11961196
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)