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

feat: improve typing of Type #1408

Merged
merged 1 commit into from
Jun 10, 2023
Merged
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
24 changes: 12 additions & 12 deletions packages/ts-morph/src/compiler/types/Type.ts
Original file line number Diff line number Diff line change
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