Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type error when using loadAll function. #658

Closed
revnelson opened this issue Oct 28, 2022 · 3 comments · Fixed by #659
Closed

Type error when using loadAll function. #658

revnelson opened this issue Oct 28, 2022 · 3 comments · Fixed by #659

Comments

@revnelson
Copy link

Describe the bug

There is a type error showing in VS Code when using the loadAll function. The full error code is:

Argument of type 'Promise<{ GetMainMenu: GetMainMenuStore; }>' is not assignable to parameter of type 'LoadAllInput'.
  Type 'Promise<{ GetMainMenu: GetMainMenuStore; }>' is not assignable to type 'LoadResult'.
    Type '{ GetMainMenu: GetMainMenuStore; }' is not assignable to type '{ [key: string]: QueryStore<any, {}, {}>; }'.
      Property 'GetMainMenu' is incompatible with index signature.
        Type 'GetMainMenuStore' is not assignable to type 'QueryStore<any, {}, {}>'.
          Types of property 'store' are incompatible.
            Type 'Writable<{ data: GetMainMenu$result | null; errors: { message: string; }[] | null; isFetching: boolean; partial: boolean; source: DataSource | null; variables: null; }>' is not assignable to type 'Writable<{ data: any; errors: { message: string; }[] | null; isFetching: boolean; partial: boolean; source: DataSource | null; variables: {}; }>'.
              Type '{ data: GetMainMenu$result | null; errors: { message: string; }[] | null; isFetching: boolean; partial: boolean; source: DataSource | null; variables: null; }' is not assignable to type '{ data: any; errors: { message: string; }[] | null; isFetching: boolean; partial: boolean; source: DataSource | null; variables: {}; }'.
                Types of property 'variables' are incompatible.
                  Type 'null' is not assignable to type '{}'.ts(2345)

As far as I can tell, I am using the function exactly as stated in the Deep Dive: Loading multiple stores simultaneously section of the docs. It seems to work as intended, just gives that dreaded red squiggly.

Additionally, types are not inferred/generated when using the loadAll function, so I'm currently having to use it as follows to get types working in the svelte page:

...((await loadAll(
	load_GetMainMenu({ event }),
	load_GetCart({ event }),
	load_GetCurrentUser({ event }),
)) as unknown as {
	GetMainMenu: GetMainMenuStore
	GetCart: GetCartStore
	GetCurrentUser: GetCurrentUserStore
}),

Severity

annoyance

Steps to Reproduce the Bug

Add the loadAll function to a +page.ts or +layout.ts file.

Reproduction

No response

@AlecAivazis
Copy link
Collaborator

AlecAivazis commented Oct 28, 2022

Ouch, okay thanks for reporting this. I'll try to find some time over the weekend to address it

@AlecAivazis
Copy link
Collaborator

Found some time to look at this over lunch and I think This is specified correctly

image

Admittedly, I'm not the strongest with typescript so i could be missing something. I'm going to try to get some help with this but if you have any ideas for how to fix this, I'm all ears. I suppose worst case scenario you will just have to pass the return type as a generic parameter to loadAll

@AlecAivazis
Copy link
Collaborator

Okay, I reached out to some people and I think they found a solution. I'm honestly amazed how quickly they came up with it. I haven't taken the time to test it in the e2e tests but on the surface it does seem to work. Leave the link here for future me: link.

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 a pull request may close this issue.

2 participants