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 Inference breaks with bundler resolution #593

Closed
nuraeil opened this issue Feb 9, 2024 · 2 comments · Fixed by #597
Closed

Type Inference breaks with bundler resolution #593

nuraeil opened this issue Feb 9, 2024 · 2 comments · Fixed by #597
Labels

Comments

@nuraeil
Copy link

nuraeil commented Feb 9, 2024

Environment

Describe the bug

With the switch in Nuxt version 3.10 to defaulting to the bundler resolution, this plugins type inference fully breaks. When using strict, the build process stops and throws the following error:

components/Bet/Moderation/AddRaceEntry.vue:508:18 - error TS7031: Binding element 'id' implicitly has an 'any' type.

This is what is displayed in VS Code when hovering over the variable for the destructured data.

image

Expected behaviour

When turning bundler resolution off, everything builds and type inference works.

nuxt.config.ts

future: {
  typescriptBundlerResolution: false,
},
image

Reproduction

https://stackblitz.com/edit/github-ohfhqq

Additional context

No response

Logs

No response

@nuraeil nuraeil added the bug label Feb 9, 2024
@nuraeil
Copy link
Author

nuraeil commented Feb 9, 2024

CC: @danielroe

@GreenmeisterDavid
Copy link

GreenmeisterDavid commented Feb 9, 2024

I've been stuck on trying to figure out why it does work for useQuery() but not for useLazyAsyncQuery() / useAsyncQuery() all morning, glad I came across your post!

I didnt figure out it was due to the bundler and made a quick wrapper to keep TS-support for now;

composables/useTypedLazyAsyncQuery.ts;

import type { DocumentNode } from "graphql";

export function useTypedLazyAsyncQuery<T>(
    query: DocumentNode
): Ref<T | undefined> {
    const { data } = await useLazyAsyncQuery<T>(query);
    return computed(() => data.value as T);
}

usage:

import type { GetShopsPreviewResult } from "~/types/generated/index"

import { GET_SHOPS_PREVIEW } from '~/graphql/queries/shops/getShopsPreview';
import { useTypedLazyAsyncQuery } from '@/composables/useTypedLazyAsyncQuery';

const data = await useTypedLazyAsyncQuery<GetShopsPreviewResult>(GET_SHOPS_PREVIEW);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants