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

error TS4058 caused by RawSymbol #7048

Closed
RomainLanz opened this issue Nov 7, 2022 · 8 comments · Fixed by #6380
Closed

error TS4058 caused by RawSymbol #7048

RomainLanz opened this issue Nov 7, 2022 · 8 comments · Fixed by #6380
Labels
🍰 p2-nice-to-have Priority 2: this is not breaking anything but nice to have it addressed. has PR A pull request has already been submitted to solve the issue scope: types

Comments

@RomainLanz
Copy link

Vue version

3.2.41

Link to minimal reproduction

https://stackblitz.com/edit/vitejs-vite-f88icu?file=src/use-foo.ts

Steps to reproduce

Note: Similar to #2548

  1. Create a project using TypeScript and Vue 3
  2. Use the @vue/tsconfig config
  3. Create a composable with markRaw
export function useFoo() {
  return markRaw({ foo: 'bar' })
}

What is expected?

TypeScript should be happy

What is actually happening?

TypeScript raises an error.

TS4058: Return type of exported function has or is using name 'RawSymbol' from external module "~/workspace/node_modules/.pnpm/@vue+reactivity@3.2.41/node_modules/@vue/reactivity/dist/reactivity" but cannot be named.

System Info

No response

Any additional comments?

No response

@RomainLanz RomainLanz changed the title RawSymbol should be exported to allow TypeScript to infer type error TS4058 caused by RawSymbol Nov 7, 2022
@baiwusanyu-c
Copy link
Member

You can turn off composite to temporarily circumvent this problem 👀

@sxzz sxzz added has PR A pull request has already been submitted to solve the issue 🍰 p2-nice-to-have Priority 2: this is not breaking anything but nice to have it addressed. labels Nov 7, 2022
yyx990803 pushed a commit that referenced this issue Nov 8, 2022
@RomainLanz
Copy link
Author

Hey there! 👋🏻

This was fixed in 3.2.41, but it seems to happen again in 3.2.45.

TS4058: Return type of exported function has or is using name 'RawSymbol' from external module "/workspace/node_modules/.pnpm/@vue+reactivity@3.2.45/node_modules/@vue/reactivity/dist/reactivity" but cannot be named.

@sxzz
Copy link
Member

sxzz commented Jan 11, 2023

@RomainLanz Could you please provide a minimum reproduction repo?

@RomainLanz
Copy link
Author

Sure, it happens when using a "complex" typing from @tanstack/vue-query.

async function fetchFoo() {
  return markRaw({ foo: 'bar' });
}

export function useFoo(options?: UseQueryOptions<Awaited<ReturnType<typeof fetchFoo>>>) {
  return useQuery({
    queryKey: ['foo'],
    queryFn: fetchFoo,
    ...options
  })
}

Without using UseQueryOptions, the issue disappears.

I created a Stackblitz here: https://stackblitz.com/edit/vitejs-vite-zwx4la?file=src%2Fuse-foo.ts

@sxzz
Copy link
Member

sxzz commented Jan 11, 2023

It seems to be an issue with TypeScript, maybe. Bulit-in Awaited will break the Raw type.

Try this one:

+++ type Awaited<T> = T extends PromiseLike<infer U> ? U : T

export function useFoo(
  options?: UseQueryOptions<Awaited<Raw<{ foo: string }>>>
) {
  return useQuery({
    queryKey: ['foo'],
    queryFn: fetchFoo,
    ...options
  })
}

@RomainLanz
Copy link
Author

Yes, it does fix it!

@klausXR
Copy link

klausXR commented Jan 30, 2023

So, are we supposed to copy-paste this code everywhere? I don't really like this solution

@sxzz
Copy link
Member

sxzz commented Jan 30, 2023

@klausXR Awaited I provided is not the same as the TypeScript built-in one.

chrislone pushed a commit to chrislone/core that referenced this issue Feb 4, 2023
zhangzhonghe pushed a commit to zhangzhonghe/core that referenced this issue Apr 12, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Sep 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🍰 p2-nice-to-have Priority 2: this is not breaking anything but nice to have it addressed. has PR A pull request has already been submitted to solve the issue scope: types
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants