Cannot assign to Type

import { scope, Type } from "arktype";

const ValidationErrorResponse = scope({
ErrorDescription: {
message: "string",
code: "'VALIDATION'",
},
Response: {
code: "400",
contents: {
errors: "ErrorDescription[]>0",
},
},
}).export().Response;

const mytype: Type = ValidationErrorResponse;
import { scope, Type } from "arktype";

const ValidationErrorResponse = scope({
ErrorDescription: {
message: "string",
code: "'VALIDATION'",
},
Response: {
code: "400",
contents: {
errors: "ErrorDescription[]>0",
},
},
}).export().Response;

const mytype: Type = ValidationErrorResponse;
This works fine in version 2.0.0-dev.19. However, updating to 2.0.0-dev.20 or above it throws this error:
Type 'Type<{ code: 400; contents: { errors: of<{ message: string; code: "VALIDATION"; }[], MoreThanLength<0>>; }; }, { Response: { code: 400; contents: { errors: of<{ message: string; code: "VALIDATION"; }[], MoreThanLength<...>>; }; }; ErrorDescription: { ...; }; }>' is not assignable to type 'Type<unknown, {}>'.
The types returned by '$.type(...)' are incompatible between these types.
Type 'Type<any, { Response: { code: 400; contents: { errors: of<{ message: string; code: "VALIDATION"; }[], MoreThanLength<0>>; }; }; ErrorDescription: { message: string; code: "VALIDATION"; }; }>' is not assignable to type 'Type<any, {}>'.
Type '{}' is not assignable to type '{ Response: { code: 400; contents: { errors: of<{ message: string; code: "VALIDATION"; }[], MoreThanLength<0>>; }; }; ErrorDescription: { message: string; code: "VALIDATION"; }; }'.
Type 'Type<{ code: 400; contents: { errors: of<{ message: string; code: "VALIDATION"; }[], MoreThanLength<0>>; }; }, { Response: { code: 400; contents: { errors: of<{ message: string; code: "VALIDATION"; }[], MoreThanLength<...>>; }; }; ErrorDescription: { ...; }; }>' is not assignable to type 'Type<unknown, {}>'.
The types returned by '$.type(...)' are incompatible between these types.
Type 'Type<any, { Response: { code: 400; contents: { errors: of<{ message: string; code: "VALIDATION"; }[], MoreThanLength<0>>; }; }; ErrorDescription: { message: string; code: "VALIDATION"; }; }>' is not assignable to type 'Type<any, {}>'.
Type '{}' is not assignable to type '{ Response: { code: 400; contents: { errors: of<{ message: string; code: "VALIDATION"; }[], MoreThanLength<0>>; }; }; ErrorDescription: { message: string; code: "VALIDATION"; }; }'.
2 Replies
ssalbdivad
ssalbdivad4mo ago
Type accepts two generic parameters, the second of which is the current scope defaulting to {}. I had previously defaulted the scope to any to avoid this kind of scenario and ensure all Type instance were assignable to Type with no params, but I think defaulting the scope to any (meaning you can chain arbitrary keywords that don't exist) is more likely to cause problems:
declare const t: Type<{}, any>

// this is probably a mistake but isn't a type error
const z = t.and({ a: "fofdsafdfso" })
declare const t: Type<{}, any>

// this is probably a mistake but isn't a type error
const z = t.and({ a: "fofdsafdfso" })
Maybe I will add UnknownType for that in the next release. In the meantime feel free to use Type<unknown, any> which should allow all types
SynthLuvr
SynthLuvr4mo ago
Thanks, that works
Want results from more Discord servers?
Add your server