Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reorder visitType check to fix bug #89

Merged
merged 1 commit into from
Mar 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/transform-inline/visitor-type-check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -694,9 +694,7 @@ function visitIndexedAccessType(type: ts.IndexedAccessType, visitorContext: Visi
}

export function visitType(type: ts.Type, visitorContext: VisitorContext): string {
if (type.aliasTypeArguments && visitorContext.previousTypeReference !== type && (type as ts.TypeReference).target) {
return visitTypeAliasReference(type as ts.TypeReference, visitorContext);
} else if ((ts.TypeFlags.Any & type.flags) !== 0) {
if ((ts.TypeFlags.Any & type.flags) !== 0) {
// Any
return visitAny(visitorContext);
} else if ((ts.TypeFlags.Unknown & type.flags) !== 0) {
Expand Down Expand Up @@ -729,6 +727,8 @@ export function visitType(type: ts.Type, visitorContext: VisitorContext): string
} else if (tsutils.isTypeReference(type) && visitorContext.previousTypeReference !== type) {
// Type references.
return visitTypeReference(type, visitorContext);
} else if (type.aliasTypeArguments && visitorContext.previousTypeReference !== type && (type as ts.TypeReference).target) {
return visitTypeAliasReference(type as ts.TypeReference, visitorContext);
} else if ((ts.TypeFlags.TypeParameter & type.flags) !== 0) {
// Type parameter
return visitTypeParameter(type, visitorContext);
Expand Down
26 changes: 26 additions & 0 deletions test/issue-88.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import * as assert from 'assert';
import { is } from '../index';

/* https://github.com/woutervh-/typescript-is/issues/88 */

interface Z<T> {
field: T;
}

type Y<T> = Z<T>

type X = Y<string>

describe('is', () => {
describe('Parameterised type alias of a parameterised type alias of an interface', () => {
it('should return true for object with field type string', () => {
assert.deepStrictEqual(is<X>({ field: 'some-string' }), true);
});
it('should return false for object with field type number', () => {
assert.deepStrictEqual(is<X>({ field: 0 }), false);
});
it('should return false for object without field', () => {
assert.deepStrictEqual(is<X>({}), false);
});
});
});