A
arktype•6mo ago
SynthLuvr

Property 'name' is missing in type

const MyErrorResponse = scope({
Error: {
message: "string",
code: "string",
},
Response: {
code: "number==500",
contents: {
errors: "Error[]",
},
},
}).export().Response;
type MyErrorResponse = typeof MyErrorResponse.infer;

const createErrorResponse = (): MyErrorResponse => {
return {
code: 500,
contents: {
errors: [{ message: "example", code: "ERROR" }],
},
};
};
const MyErrorResponse = scope({
Error: {
message: "string",
code: "string",
},
Response: {
code: "number==500",
contents: {
errors: "Error[]",
},
},
}).export().Response;
type MyErrorResponse = typeof MyErrorResponse.infer;

const createErrorResponse = (): MyErrorResponse => {
return {
code: 500,
contents: {
errors: [{ message: "example", code: "ERROR" }],
},
};
};
This results in error:
Property 'name' is missing in type '{ message: string; code: string; }' but required in type '{ message: string; code: string; name: never; stack?: undefined; cause?: undefined; }'.
Property 'name' is missing in type '{ message: string; code: string; }' but required in type '{ message: string; code: string; name: never; stack?: undefined; cause?: undefined; }'.
This can be resolved by using type:
const MyErrorResponse = scope({
Error: type({
message: "string",
code: "string",
}),
Response: {
code: "number==500",
contents: {
errors: "Error[]",
},
},
}).export().Response;
const MyErrorResponse = scope({
Error: type({
message: "string",
code: "string",
}),
Response: {
code: "number==500",
contents: {
errors: "Error[]",
},
},
}).export().Response;
Is this the intended usage, or a bug? Because I was expecting that type would be implied within scope
5 Replies
ssalbdivad
ssalbdivad•6mo ago
I'm not seeing the error on my end 🤔 Ohhhhh I do know why this is happening though it is fixed by an unreleased changed to allow overriding builtin keywords What you're seeing is that Error doesn't know what to resolve to essentially since there is also a default Error keyword representing the builtin class. If you wrap it in type, it just bypasses your scope and resolves to the builtin
SynthLuvr
SynthLuvrOP•6mo ago
ah makes sense
ssalbdivad
ssalbdivad•6mo ago
I will release this now @SynthLuvr Also you can write number literals directly like in TS e.g. 500 The == just works for consistency with other comparisons since it is needed for length E.g. if you wanted a 2-char string you'd want string==2. number<2 is useful but number==2 is basically just so the same comparators ==, <=, >=, >, and < work everywhere
SynthLuvr
SynthLuvrOP•6mo ago
Ah yes it works. I swear I tried doing that in the past but got errors. idk if I was imagining it or if a bug was fixed. But I'll use the literals now
ssalbdivad
ssalbdivad•6mo ago
Nah that has been stable since pre-alpha 😅 The static parser has barely seen any changes really over the last year since that was the focus of most of the initial dev effort and turned out well (other than adding a few new features)
Want results from more Discord servers?
Add your server