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

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

Closed
ajvincent opened this issue Jul 7, 2022 · 1 comment
Closed

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

ajvincent opened this issue Jul 7, 2022 · 1 comment

Comments

@ajvincent
Copy link
Contributor

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
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants