Type '"DateValue | undefined"' is not assignable to type '"'DateValue' is unresolvable "'.ts(2322)

Hello, i am an absolute beginner when it comes to ArkType and i am trying adapt my project while following allowing the https://arktype.io/docs/intro/your-first-type intro. When trying to adopt the example to my real life type, i am getting the error mentioned in the title. DateValue itself is a union type of some classes. What i am doing wrong?
ArkType
ArkType Docs
TypeScript's 1:1 validator, optimized from editor to runtime
No description
8 Replies
TizzySaurus
TizzySaurus6d ago
You're importing DateValue as a TS type, so it doesn't even exist at runtime [when arktype runs] What actually is DateValue? You probably need to create an arktype type equivalent and use that I.e.
import type { DateValue } from "...";
import { type } from "arktype";

const DateValue = type(...).as<DateValue>();

export const arcEditObject = type({
...
start: [DateValue, "|", "undefined"]
});
import type { DateValue } from "...";
import { type } from "arktype";

const DateValue = type(...).as<DateValue>();

export const arcEditObject = type({
...
start: [DateValue, "|", "undefined"]
});
Frieder
FriederOP6d ago
DateValue is a union type of some classes that i am forced to use because its a dependency of the shadcn date picker.
No description
TizzySaurus
TizzySaurus6d ago
Right... I guess you'd need an equivalent ArkType type for each of those classes then Well, actually, I think there's a type.instanceOf or something Yeah, there is, so something like
import { DateValue } from "..."; // NB: NOT a type import
import { type } from "arktype";

const DateValue = type.instanceOf(DateValue);

export const arcEditObject = type({
...
start: [DateValue, "|", "undefined"]
});
import { DateValue } from "..."; // NB: NOT a type import
import { type } from "arktype";

const DateValue = type.instanceOf(DateValue);

export const arcEditObject = type({
...
start: [DateValue, "|", "undefined"]
});
should work @Frieder
Frieder
FriederOP6d ago
Thanks! Unfortunately, in order to make it work it seems that i would have to change some tsconfig.ts settings that are at least recommended by svelte, including setting "verbatimModuleSyntax" to false and also "isolatedModules". But even if i do this, i does not work and i get an as shown in the picture. Renaming '''const DateValue = type.instanceOf(DateValue);''' to something else results in "DateValue' only refers to a type, but is being used as a value here.ts(2693)"
No description
TizzySaurus
TizzySaurus6d ago
Right yeah, the import isn't type-only anymore so you can't name the ArkType type the same Using a different name should work though (make sure to update the other references)
Frieder
FriederOP6d ago
I tried it but it doesn't 😦
No description
TizzySaurus
TizzySaurus6d ago
Oh, right, DateValue is a type not a class So you'll need to recreate from the actual classes I.e. type.instanceOf(CalendarDate).or(type.instanceOf(CalendarDateTime).or(type.instanceOf(ZonedDateTime).as<DateValue>() (and I'd make DateValue a type import again for clarity)
Frieder
FriederOP6d ago
Many thanks, that did the trick and i could also switch back to the recommened ts settings Many thanks!

Did you find this page helpful?