From 808fce44312e770458c3d1d00d31b55e4c25f78b Mon Sep 17 00:00:00 2001 From: Kaido Iwamoto Date: Wed, 10 May 2023 16:23:05 +0900 Subject: [PATCH] chore: improve typing of `Type` --- packages/ts-morph/src/compiler/types/Type.ts | 24 ++++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/ts-morph/src/compiler/types/Type.ts b/packages/ts-morph/src/compiler/types/Type.ts index d41b527ef..cfddb07c1 100644 --- a/packages/ts-morph/src/compiler/types/Type.ts +++ b/packages/ts-morph/src/compiler/types/Type.ts @@ -285,7 +285,7 @@ export class Type { if (!this.isUnion()) return []; - return (this.compilerType as any as ts.UnionType).types.map(t => this._context.compilerFactory.getType(t)); + return this.compilerType.types.map(t => this._context.compilerFactory.getType(t)); } /** @@ -411,7 +411,7 @@ export class Type { /** * Gets if this is a template literal type. */ - isTemplateLiteral() { + isTemplateLiteral(): this is Type { return this._hasTypeFlag(TypeFlags.TemplateLiteral); } @@ -462,28 +462,28 @@ export class Type { /** * Gets if this is a number literal type. */ - isNumberLiteral() { + isNumberLiteral(): this is Type { return this._hasTypeFlag(TypeFlags.NumberLiteral); } /** * Gets if this is a string literal type. */ - isStringLiteral() { + isStringLiteral(): this is Type { return this.compilerType.isStringLiteral(); } /** * Gets if this is a class type. */ - isClass() { + isClass(): this is Type { return this.compilerType.isClass(); } /** * Gets if this is a class or interface type. */ - isClassOrInterface() { + isClassOrInterface(): this is Type { return this.compilerType.isClassOrInterface(); } @@ -509,14 +509,14 @@ export class Type { /** * Gets if this is an interface type. */ - isInterface() { + isInterface(): this is Type { return this._hasObjectFlag(ObjectFlags.Interface); } /** * Gets if this is an object type. */ - isObject() { + isObject(): this is Type { return this._hasTypeFlag(TypeFlags.Object); } @@ -530,7 +530,7 @@ export class Type { /** * Gets if this is a tuple type. */ - isTuple() { + isTuple(): this is Type { const targetType = this.getTargetType(); if (targetType == null) return false; @@ -540,21 +540,21 @@ export class Type { /** * Gets if this is a union type. */ - isUnion() { + isUnion(): this is Type { return this.compilerType.isUnion(); } /** * Gets if this is an intersection type. */ - isIntersection() { + isIntersection(): this is Type { return this.compilerType.isIntersection(); } /** * Gets if this is a union or intersection type. */ - isUnionOrIntersection() { + isUnionOrIntersection(): this is Type { return this.compilerType.isUnionOrIntersection(); }