Skip to content

Commit

Permalink
feat: add IsVoid method to Type (#1398)
Browse files Browse the repository at this point in the history
  • Loading branch information
giuseppelt committed Jun 10, 2023
1 parent e738204 commit f837790
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/ts-morph/src/compiler/types/Type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,13 @@ export class Type<TType extends ts.Type = ts.Type> {
isUndefined() {
return this._hasTypeFlag(TypeFlags.Undefined);
}

/**
* Gets if this is the void type.
*/
isVoid() {
return this._hasTypeFlag(TypeFlags.Void);
}

/**
* Gets the type flags.
Expand Down
15 changes: 15 additions & 0 deletions packages/ts-morph/src/tests/compiler/type/typeTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ let explicitReadonlyArrayType: ReadonlyArray<string>;
let neverType: never;
let arrayTypeOfTuples: [string][];
let undefinedType: undefined;
let voidType: void;
let classType: MyClass;
let functionType: () => string;
let constructorType: { new(): MyClass; };
Expand Down Expand Up @@ -518,6 +519,20 @@ let unknownType: unknown;
});
});

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

it("should be when is", () => {
doTest("voidType", true);
});

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

describe(nameof<Type>("getFlags"), () => {
it("should get the type flags", () => {
expect(typesByName["numberType"].getFlags()).to.equal(TypeFlags.Number);
Expand Down

0 comments on commit f837790

Please sign in to comment.