Skip to content

Commit

Permalink
feat: #538 - Add Type#isAny()
Browse files Browse the repository at this point in the history
  • Loading branch information
schiller-manuel authored and dsherret committed Feb 14, 2019
1 parent ddc1dd3 commit 1d3c2bb
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/details/types.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ Use any of the following methods:

```ts
type.isAnonymous();
type.isAny();
type.isArray();
type.isBoolean();
type.isString();
Expand Down
7 changes: 7 additions & 0 deletions src/compiler/types/Type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,13 @@ export class Type<TType extends ts.Type = ts.Type> {
return this._hasObjectFlag(ObjectFlags.Anonymous);
}

/**
* Gets if this is an any type.
*/
isAny() {
return this._hasTypeFlag(TypeFlags.Any);
}

/**
* Gets if this is an array type.
*/
Expand Down
15 changes: 15 additions & 0 deletions src/tests/compiler/type/typeTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ interface MyInterface {}
class MyClass {}
let anonymousType: { str: string; };
let anyType: any;
let stringType: string;
let booleanType: boolean;
let numberType: number;
Expand Down Expand Up @@ -116,6 +117,20 @@ let stringWithUndefinedAndNullType: string | undefined | null;
});
});

describe(nameof<Type>(t => t.isAny), () => {
function doTest(typeName: string, expected: boolean) {
expect(typesByName[typeName].isAny()).to.equal(expected);
}

it("should be when any", () => {
doTest("anyType", true);
});

it("should not be when not any", () => {
doTest("stringType", false);
});
});

describe(nameof<Type>(t => t.isBoolean), () => {
function doTest(typeName: string, expected: boolean) {
expect(typesByName[typeName].isBoolean()).to.equal(expected);
Expand Down

0 comments on commit 1d3c2bb

Please sign in to comment.