Skip to content

Commit

Permalink
feat: Add Type: isUnionOrIntersection, isClass, and isClassOrInterface.
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Renamed all Type.isXType() methods to Type.isX() to match what's done in the compiler api and to remove needless repetition in name.
  • Loading branch information
dsherret committed Jun 2, 2018
1 parent da45aae commit 12c4710
Show file tree
Hide file tree
Showing 6 changed files with 203 additions and 111 deletions.
36 changes: 21 additions & 15 deletions docs/details/types.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,21 +197,27 @@ const aliasTypeArgs = type.getAliasTypeArguments();
Use any of the following methods:

```ts
type.isAnonymousType();
type.isBooleanType();
type.isStringType();
type.isNumberType();
type.isEnumType();
type.isLiteralType();
type.isBooleanLiteralType();
type.isStringLiteralType();
type.isNumberLiteralType();
type.isEnumLiteralType();
type.isIntersectionType();
type.isInterfaceType();
type.isObjectType();
type.isTupleType();
type.isUnionType();
type.isAnonymous();
type.isArray();
type.isBoolean();
type.isString();
type.isNumber();
type.isClass();
type.isClassOrInterface();
type.isEnum();
type.isInterface();
type.isLiteral();
type.isBooleanLiteral();
type.isStringLiteral();
type.isNumberLiteral();
type.isEnumLiteral();
type.isObject();
type.isTuple();
type.isUnion();
type.isIntersection();
type.isUnionOrIntersection();
type.isNull();
type.isUndefined();
```

If you see something that doesn't exist here and should (there's a lot missing), then please log an issue or submit a pull request.
Expand Down
61 changes: 37 additions & 24 deletions lib/ts-simple-ast.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8635,85 +8635,98 @@ export declare class Type<TType extends ts.Type = ts.Type> {
/**
* Gets if this is an anonymous type.
*/
isAnonymousType(): boolean;
isAnonymous(): boolean;
/**
* Gets if this is an array type.
*/
isArrayType(): boolean;
isArray(): boolean;
/**
* Gets if this is a boolean type.
*/
isBooleanType(): boolean;
isBoolean(): boolean;
/**
* Gets if this is a string type.
*/
isStringType(): boolean;
isString(): boolean;
/**
* Gets if this is a number type.
*/
isNumberType(): boolean;
isNumber(): boolean;
/**
* Gets if this is a literal type.
*/
isLiteralType(): boolean;
isLiteral(): boolean;
/**
* Gets if this is a boolean literal type.
*/
isBooleanLiteralType(): boolean;
isBooleanLiteral(): boolean;
/**
* Gets if this is an enum literal type.
*/
isEnumLiteralType(): boolean;
isEnumLiteral(): boolean;
/**
* Gets if this is a literal string type.
* Gets if this is a number literal type.
*/
isStringLiteralType(): boolean;
isNumberLiteral(): boolean;
/**
* Gets if this is a literal number type.
* Gets if this is a string literal type.
*/
isNumberLiteralType(): boolean;
isStringLiteral(): boolean;
/**
* Gets if this is an enum type.
* Gets if this is a class type.
*/
isEnumType(): boolean;
isClass(): boolean;
/**
* Gets if this is an interface type.
* Gets if this is a class or interface type.
*/
isInterfaceType(): boolean;
isClassOrInterface(): boolean;
/**
* Gets if this is an intersection type.
* Gets if this is an enum type.
*/
isIntersectionType(): boolean;
isEnum(): boolean;
/**
* Gets if this is the null type.
* Gets if this is an interface type.
*/
isNullType(): boolean;
isInterface(): boolean;
/**
* Gets if this is an object type.
*/
isObjectType(): boolean;
isObject(): boolean;
/**
* Gets if this is a type parameter.
*/
isTypeParameter(): this is TypeParameter;
/**
* Gets if this is a tuple type.
*/
isTupleType(): boolean;
isTuple(): boolean;
/**
* Gets if this is a union type.
*/
isUnionType(): boolean;
isUnion(): boolean;
/**
* Gets if this is an intersection type.
*/
isIntersection(): boolean;
/**
* Gets if this is a union or intersection type.
*/
isUnionOrIntersection(): boolean;
/**
* Gets if this is the null type.
*/
isNull(): boolean;
/**
* Gets if this is the undefined type.
*/
isUndefinedType(): boolean;
isUndefined(): boolean;
/**
* Gets the type flags.
*/
getFlags(): TypeFlags;
/**
* Gets the object flags.
* @remarks Returns 0 for a non-object type.
*/
getObjectFlags(): 0 | ObjectFlags;
private _hasTypeFlag;
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/class/ClassDeclaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ export class ClassDeclaration extends ClassDeclarationBase<ts.ClassDeclaration>
* Note: Use getBaseTypes if you need to get the mixins.
*/
getBaseClass() {
const baseTypes = ArrayUtils.flatten(this.getBaseTypes().map(t => t.isIntersectionType() ? t.getIntersectionTypes() : [t]));
const baseTypes = ArrayUtils.flatten(this.getBaseTypes().map(t => t.isIntersection() ? t.getIntersectionTypes() : [t]));
const declarations = baseTypes
.map(t => t.getSymbol())
.filter(s => s != null)
Expand Down

0 comments on commit 12c4710

Please sign in to comment.