Skip to content

Conversation

@erwan-joly
Copy link

@erwan-joly erwan-joly commented Jun 8, 2023

@Code-Hex this partially fix #359
unfortunately when having outer type field mandatory we are still having an issue

type InnerType2 {
  testScalar: MyScalar
}

type OuterType2 {
  inner: InnerType2!
}

throw the error

error TS1360: Type 'ObjectSchema<{ __typename: "OuterType2" | undefined; inner: any; }, AnyObject, { __typename: undefined; inner: any; }, "">' does not satisfy the expected type 'ObjectSchema<OuterType2, AnyObject, any, "">'.
  The types of 'default(...).__outputType' are incompatible between these types.
    Type '{ __typename?: "OuterType2" | undefined; inner?: any; }' is not assignable to type '{ __typename?: "OuterType2" | undefined; inner: InnerType2; }'.
      Property 'inner' is optional in type '{ __typename?: "OuterType2" | undefined; inner?: any; }' but required in type '{ __typename?: "OuterType2" | undefined; inner: InnerType2; }'.

@Code-Hex
Copy link
Owner

Code-Hex commented Jun 8, 2023

@erwan-joly Thank you!
However, this approach leads to the issue where the inferred type for the field becomes 'any' when it is self-referencing, which in turn prevents the 'satisfies' from compiling.

Not being able to compile would be a regression from the current situation, so I'm not convinced that this can be considered a partial fix. I'll be happy to merge if it can be confirmed that it allows for a successful compilation!

@erwan-joly
Copy link
Author

Not sure sorry just tried to apply the suggested fix on yup if there is a good fix I think that would be better

@Code-Hex
Copy link
Owner

Code-Hex commented Jun 8, 2023

@erwan-joly This is example:
スクリーンショット 2023-06-08 21 25 06

error is

$ tsc --strict --noEmit example/yup/schemas.ts
example/yup/schemas.ts:32:17 - error TS7023: 'ComponentInputSchema' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions.

32 export function ComponentInputSchema() {
                   ~~~~~~~~~~~~~~~~~~~~


Found 1 error in example/yup/schemas.ts:32

Your PR is using yup.Schema as the return type but it has not the type information is lost on the user side. If satisfies are used, the return value must not have any type of information. The results of type inference should be used instead.

@Code-Hex
Copy link
Owner

Code-Hex commented Dec 9, 2023

Temporary close this PR.

@Code-Hex Code-Hex closed this Dec 9, 2023
@Code-Hex Code-Hex mentioned this pull request Dec 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bugs with yup v1 and arrays of non nullable

2 participants