Skip to content

Commit

Permalink
chore: improve typing of Type (#1408)
Browse files Browse the repository at this point in the history
  • Loading branch information
odiak committed Jun 10, 2023
1 parent fe9042b commit e738204
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions packages/ts-morph/src/compiler/types/Type.ts
Expand Up @@ -285,7 +285,7 @@ export class Type<TType extends ts.Type = ts.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));
}

/**
Expand Down Expand Up @@ -411,7 +411,7 @@ export class Type<TType extends ts.Type = ts.Type> {
/**
* Gets if this is a template literal type.
*/
isTemplateLiteral() {
isTemplateLiteral(): this is Type<ts.TemplateLiteralType> {
return this._hasTypeFlag(TypeFlags.TemplateLiteral);
}

Expand Down Expand Up @@ -462,28 +462,28 @@ export class Type<TType extends ts.Type = ts.Type> {
/**
* Gets if this is a number literal type.
*/
isNumberLiteral() {
isNumberLiteral(): this is Type<ts.NumberLiteralType> {
return this._hasTypeFlag(TypeFlags.NumberLiteral);
}

/**
* Gets if this is a string literal type.
*/
isStringLiteral() {
isStringLiteral(): this is Type<ts.StringLiteralType> {
return this.compilerType.isStringLiteral();
}

/**
* Gets if this is a class type.
*/
isClass() {
isClass(): this is Type<ts.InterfaceType> {
return this.compilerType.isClass();
}

/**
* Gets if this is a class or interface type.
*/
isClassOrInterface() {
isClassOrInterface(): this is Type<ts.InterfaceType> {
return this.compilerType.isClassOrInterface();
}

Expand All @@ -509,14 +509,14 @@ export class Type<TType extends ts.Type = ts.Type> {
/**
* Gets if this is an interface type.
*/
isInterface() {
isInterface(): this is Type<ts.InterfaceType> {
return this._hasObjectFlag(ObjectFlags.Interface);
}

/**
* Gets if this is an object type.
*/
isObject() {
isObject(): this is Type<ts.ObjectType> {
return this._hasTypeFlag(TypeFlags.Object);
}

Expand All @@ -530,7 +530,7 @@ export class Type<TType extends ts.Type = ts.Type> {
/**
* Gets if this is a tuple type.
*/
isTuple() {
isTuple(): this is Type<ts.TupleType> {
const targetType = this.getTargetType();
if (targetType == null)
return false;
Expand All @@ -540,21 +540,21 @@ export class Type<TType extends ts.Type = ts.Type> {
/**
* Gets if this is a union type.
*/
isUnion() {
isUnion(): this is Type<ts.UnionType> {
return this.compilerType.isUnion();
}

/**
* Gets if this is an intersection type.
*/
isIntersection() {
isIntersection(): this is Type<ts.IntersectionType> {
return this.compilerType.isIntersection();
}

/**
* Gets if this is a union or intersection type.
*/
isUnionOrIntersection() {
isUnionOrIntersection(): this is Type<ts.UnionOrIntersectionType> {
return this.compilerType.isUnionOrIntersection();
}

Expand Down

0 comments on commit e738204

Please sign in to comment.