How to include an external class into an arktype type?
I tried
and
but both create a Type<never> for me.
I'm using arktype 1.0.29-alpha
19 Replies
The second should work, are you able to repro it with the class definition or some minimal case?
Not exactly sure what you mean, but this is the "TimeStub" class:
And if I try to inlcude it into type() it has the Type<never> type (Screenshot attached)

I would guess the problem is the private constructor
Sorry wrong image one sec

You can use a cast to get around it like this:
With that is shows me ts as undefined

That's weird I just tested that with your example and it worked
Are you tested it with 2.0.0? Because I'm on 1.0.29-alpha
I was looking at .27-alpha, is
strict
enabled?you mean in
tsconfig.json
? Yeshttps://stackblitz.com/edit/rzkceh-2zawsh?file=demo.ts
Maybe it's a TS version thing? Can you repro it here?
I tested with 5.0 and 5.4 it seems like it works on both
On your stackblitz I see it working - that's good - now I need to find out what's wrong with my machine/setup 😉
Yeah that's very bizarre I have no idea what it would be
I'm still not sure why the
undefined
happens, but I was able to create a reproduction for this: https://github.com/arktypeio/arktype/issues/916GitHub
Type ['instanceof', TimeStub] as Infer is undefined · Issue #916 · ...
Report a bug @ssalbdivad I have created a reproduction of yesterday's undefined problem Discord Discussion. 🧩 Context ArkType version: 1.0.29-alpha TypeScript version (4.8+): 5.4.2 Other contex...
Thanks for the repro, just added a comment! Should be an easy one to resolve by changing the
.d.ts
file to a .ts
file.Has the way changed in v2 of getting the Arktype of a TS class with a private constructor? @ssalbdivad
type(['instanceof', TimeStub] as Infer<TimeStub>);
is not more working for me. It tells me, Cannot find name "Infer". Did you mean "NoInfer"?
I think you can
Anyways, now it's
type.cast<>

Yes I have this in my unit tests now 😊
