ts-morph icon indicating copy to clipboard operation
ts-morph copied to clipboard

type.isNever() should exist to report a 'never' type

Open ajvincent opened this issue 3 years ago • 1 comments

Describe the bug

Version: 15.1.0 https://ts-morph.com/details/types#telling-type

To Reproduce

type neverProperty = {
  illegal: never;
}
import { Project } from "ts-morph";

const project = new Project();
const sourceFile = project.createSourceFile("test.ts", ``);

it("Type.prototype.isNever() returns true for a never type", () => {
  const neverPropertyNode = sourceFile.getTypeAliasOrThrow("neverProperty");
  const neverPropertyType = neverPropertyNode.getType();
  const illegalType = neverPropertyType.getProperty("illegal").getTypeAtLocation(neverPropertyNode);

  // throws because Type doesn't have an `isNever()` method`
  expect(illegalType.isNever()).toBe(true);
  expect(neverPropertyType.isNever()).toBe(false);
});

Expected behavior

illegalType.isNever() should return true. neverPropertyType.isNever() should return false.

ajvincent avatar Jul 07 '22 17:07 ajvincent

This looks trivial to implement: typeAtNode.getFlags() & ts.TypeFlags.Never. But I don't have deno installed as npm run setup seems to require.

ajvincent avatar Jul 07 '22 17:07 ajvincent