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.
According to documentation,
instance()
should be the equivalent ofinstanceof
. 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:
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.