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

instance causes a TypeScript error with abstract classes #1192

Open
matthew-dean opened this issue Nov 12, 2023 · 0 comments
Open

instance causes a TypeScript error with abstract classes #1192

matthew-dean opened this issue Nov 12, 2023 · 0 comments

Comments

@matthew-dean
Copy link

According to documentation, instance() should be the equivalent of instanceof. However, it causes a TypeScript error when used with an abstract class.

See: https://stackblitz.com/edit/arktype-bug-srv9n6?file=demo.ts

This code fails:

import { type, instance, assert } from 'superstruct';

abstract class Node {}

class SubNode extends Node {}

export const shouldPass = type({
  node: instance(Node),
});

const sub = new SubNode();
const isNode = sub instanceof Node;

export const result = assert({ node: sub }, shouldPass);

Error is Argument of type 'typeof Node' is not assignable to parameter of type 'new (...args: any) => any'. Cannot assign an abstract constructor type to a non-abstract constructor type.

matthew-dean added a commit to matthew-dean/superstruct that referenced this issue Nov 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant