tinacms icon indicating copy to clipboard operation
tinacms copied to clipboard

generated types in `types.ts` do not match responses from client

Open danielknell opened this issue 2 years ago • 0 comments

Description

Types in types.ts do not match the types returned by the client.

I have seen a bunch of similar errors caused by references and

Steps to reproduce

run tsc against the following code:

import * as types from "tinacms-types";

const foo = (obj: types.PostConnectionQuery): types.PostConnection => {
  return obj.postConnection;
};

const bar = (
  obj: types.PostConnectionQuery
): Omit<types.PostConnection, "pageInfo"> => {
  return obj.postConnection;
};

Expected result

No errors

Actual result

foo.ts:4:3 - error TS2322: Type '{ __typename?: "PostConnection" | undefined; totalCount: number; edges?: ({ __typename?: "PostConnectionEdges" | undefined; node?: { __typename?: "Post" | undefined; id: string; title: string; ... 6 more ...; series?: { ...; } | ... 1 more ... | undefined; } | null | undefined; } | null)[] | null | undefined; }' is not assignable to type 'PostConnection'.
  Property 'pageInfo' is missing in type '{ __typename?: "PostConnection" | undefined; totalCount: number; edges?: ({ __typename?: "PostConnectionEdges" | undefined; node?: { __typename?: "Post" | undefined; id: string; title: string; ... 6 more ...; series?: { ...; } | ... 1 more ... | undefined; } | null | undefined; } | null)[] | null | undefined; }' but required in type 'Connection'.

4   return obj.postConnection;
    ~~~~~~~~~~~~~~~~~~~~~~~~~~

  .tina/__generated__/types.ts:66:3
    66   pageInfo: PageInfo;
         ~~~~~~~~
    'pageInfo' is declared here.

foo.ts:10:3 - error TS2322: Type '{ __typename?: "PostConnection" | undefined; totalCount: number; edges?: ({ __typename?: "PostConnectionEdges" | undefined; node?: { __typename?: "Post" | undefined; id: string; title: string; ... 6 more ...; series?: { ...; } | ... 1 more ... | undefined; } | null | undefined; } | null)[] | null | undefined; }' is not assignable to type 'Omit<PostConnection, "pageInfo">'.
  Types of property 'edges' are incompatible.
    Type '({ __typename?: "PostConnectionEdges" | undefined; node?: { __typename?: "Post" | undefined; id: string; title: string; date: string; tags: string[]; excerpt?: string | null | undefined; body: any; _sys: { ...; }; author: { ...; }; series?: { ...; } | ... 1 more ... | undefined; } | null | undefined; } | null)[] | n...' is not assignable to type 'Maybe<Maybe<PostConnectionEdges>[]> | undefined'.
      Type '({ __typename?: "PostConnectionEdges" | undefined; node?: { __typename?: "Post" | undefined; id: string; title: string; date: string; tags: string[]; excerpt?: string | null | undefined; body: any; _sys: { ...; }; author: { ...; }; series?: { ...; } | ... 1 more ... | undefined; } | null | undefined; } | null)[]' is not assignable to type 'Maybe<PostConnectionEdges>[]'.
        Type '{ __typename?: "PostConnectionEdges" | undefined; node?: { __typename?: "Post" | undefined; id: string; title: string; date: string; tags: string[]; excerpt?: string | null | undefined; body: any; _sys: { ...; }; author: { ...; }; series?: { ...; } | ... 1 more ... | undefined; } | null | undefined; } | null' is not assignable to type 'Maybe<PostConnectionEdges>'.
          Property 'cursor' is missing in type '{ __typename?: "PostConnectionEdges" | undefined; node?: { __typename?: "Post" | undefined; id: string; title: string; date: string; tags: string[]; excerpt?: string | null | undefined; body: any; _sys: { ...; }; author: { ...; }; series?: { ...; } | ... 1 more ... | undefined; } | null | undefined; }' but required in type 'PostConnectionEdges'.

10   return obj.postConnection;
     ~~~~~~~~~~~~~~~~~~~~~~~~~~

  .tina/__generated__/types.ts:361:3
    361   cursor: Scalars['String'];
          ~~~~~~
    'cursor' is declared here.

Environment

Tinacms Package Versions

├── @tinacms/[email protected]
├── [email protected]
├── [email protected]

Tools

Tool Version
browser
os
node
npm

danielknell avatar Aug 07 '22 15:08 danielknell

Sorry for the delayed reply, thanks @danielknell for submitting this issue. I believe that #3198 will be a potential fix for this.

logan-anderson avatar Sep 15 '22 14:09 logan-anderson

Quick update.

#3198 has been merged. So you can test to see if this is fixed now by installing tinacms@beta and @tinacms/cli@beta.

logan-anderson avatar Sep 16 '22 14:09 logan-anderson