Repository navigation
Bugs with yup v1 and arrays of non nullable #359
Copy link
Copy link
Closed
Labels
pendingPending because of dependence on somethingPending because of dependence on something
Description
It seems like their is some issues with array and nullable types
export function UpdateAssessmentInputSchema(): yup.ObjectSchema<UpdateAssessmentInput> {
return yup.object({
answers: yup.array(yup.lazy(() => QuestionAnswerInputSchema().nonNullable())).defined(),
domainIndex: yup.number().defined().nonNullable(),
encodedId: yup.string().defined().nonNullable(),
groupIndex: yup.number().defined().nonNullable(),
previous: yup.boolean().defined().nonNullable(),
save: yup.boolean().defined().nonNullable()
})
}
export type UpdateAssessmentInput = {
answers: Array<QuestionAnswerInput>;
domainIndex: Scalars['Int'];
encodedId: Scalars['String'];
groupIndex: Scalars['Int'];
previous: Scalars['Boolean'];
save: Scalars['Boolean'];
};
export function QuestionAnswerInputSchema(): yup.ObjectSchema<QuestionAnswerInput> {
return yup.object({
answer: yup.string().defined().nullable().optional(),
index: yup.number().defined().nonNullable(),
multichoiceAnswers: yup.array(yup.string().defined().nonNullable()).defined()
})
}
Results in this error:
Error TS2322 (TS) Type 'ObjectSchema<{ answers: { answer?: string; index?: number; multichoiceAnswers?: string[]; }[]; domainIndex: number; encodedId: string; groupIndex: number; previous: boolean; save: boolean; }, AnyObject, { ...; }, "">' is not assignable to type 'ObjectSchema<UpdateAssessmentInput, AnyObject, any, "">'.
The types of 'default(...).fields.answers' are incompatible between these types.
Type 'Reference<unknown> | ISchema<{ answer?: string; index?: number; multichoiceAnswers?: string[]; }[], AnyObject, any, any>' is not assignable to type 'Reference<unknown> | ISchema<QuestionAnswerInput[], AnyObject, any, any>'.
Type 'ISchema<{ answer?: string; index?: number; multichoiceAnswers?: string[]; }[], AnyObject, any, any>' is not assignable to type 'Reference<unknown> | ISchema<QuestionAnswerInput[], AnyObject, any, any>'.
Type 'ISchema<{ answer?: string; index?: number; multichoiceAnswers?: string[]; }[], AnyObject, any, any>' is not assignable to type 'ISchema<QuestionAnswerInput[], AnyObject, any, any>'.
Type '{ answer?: string; index?: number; multichoiceAnswers?: string[]; }[]' is not assignable to type 'QuestionAnswerInput[]'.
Type '{ answer?: string; index?: number; multichoiceAnswers?: string[]; }' is not assignable to type 'QuestionAnswerInput'.
Property 'index' is optional in type '{ answer?: string; index?: number; multichoiceAnswers?: string[]; }' but required in type 'QuestionAnswerInput'.
For some reasons it seems like the system believe all properties of QuestionAnswerInputSchema should be nullable but in the end gets some required property and fail.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
pendingPending because of dependence on somethingPending because of dependence on something
Activity
erwan-joly commentedon Apr 27, 2023
may be related to yup jquense/yup#1890 ?
Code-Hex commentedon May 5, 2023
@erwan-joly mmm, The link mentioned to Yup v0.32 not v1.
Could you give me the QuestionAnswerInputSchema as GraphQL Schema?
I want to check it in my local too.
erwan-joly commentedon May 5, 2023
yep it's happening for me in v1 and was fine before the upgrade but thats the only thing close to my issue i could find.
here the graphql part
Code-Hex commentedon May 13, 2023
I tried this schema and type-checked with
tsc --strict --noEmit example/yup/schemas.tsbut I couldn't get build error.Do you use
"strict": true,option in tsconfig.json?You can try it!
example/test.graphqlwith your provided schema.yarn generateto generate validation schema for example code.yarn type-check:yuperwan-joly commentedon May 13, 2023
I only use
"noImplicitAny": true,
"module": "ES2022",
"target": "ES2022",
"allowSyntheticDefaultImports": true,
"jsx": "react",
"allowJs": false,
"moduleResolution": "node",
"skipLibCheck": true
will test that asap
erwan-joly commentedon May 23, 2023
@Code-Hex I've been able to reproduce the error
this as
test.graphqlwill failyarn type-check:yupSeems to be due to nested type with custom scalar field. as This schema would not fire an error
Code-Hex commentedon May 27, 2023
@erwan-joly Thanks! I submitted issue in yup
jquense/yup#2013
fix Bugs with yup v1 and arrays of non nullable fix Code-Hex#359
partialy fix Bugs with yup v1 and arrays of non nullable Code-Hex#359
Code-Hex commentedon Apr 25, 2026
Covered in #1423. The repo is now on Yup 1.7.1, and I added a strict TypeScript compile regression for arrays of non-null input objects so this case stays checked.