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

acceptHMRUpdate type error when switching to TS 5.0 #2098

Closed
josh-hemphill opened this issue Mar 23, 2023 · 3 comments · Fixed by #2152
Closed

acceptHMRUpdate type error when switching to TS 5.0 #2098

josh-hemphill opened this issue Mar 23, 2023 · 3 comments · Fixed by #2152
Labels
bug Something isn't working contribution welcome has workaround The issue contains a temporary solution to get around the problem typescript This issue is related to typings

Comments

@josh-hemphill
Copy link

Reproduction

https://github.com/josh-hemphill/pinia_bug-report

Steps to reproduce the bug

  1. Use Typescript >5.0
  2. Use Setup-style to create a store
  3. Use Hot module reload snippet if not present (acceptHMRUpdate function)
  4. Set VSCode to use workspace tsc or run tsc --noEmit
  5. Observe the error

Expected behavior

For there not to be a type error

Actual behavior

Type error is thrown:

Argument of type 'StoreDefinition<"counter", _UnwrapAll<Pick<{ n: Ref<number>; getN: () => Ref<number>; }, "n">>, Pick<{ n: Ref<number>; getN: () => Ref<number>; }, never>, Pick<...>>' is not assignable to parameter of type 'StoreDefinition<string, StateTree, _GettersTree<StateTree>, _ActionsTree>'.
  Property 'getN' is missing in type '_ActionsTree' but required in type 'Pick<{ n: Ref<number>; getN: () => Ref<number>; }, "getN">'.ts(2345)

Additional information

No response

@thisVioletHydra

This comment was marked as spam.

@samydoesit
Copy link

samydoesit commented Mar 27, 2023

Not great, but adding as any to the first parameter of acceptHMRUpdate works around it on my end.

if (import.meta.hot) {
  import.meta.hot.accept(acceptHMRUpdate(useUserStore as any, import.meta.hot));
}

or add a shim

# shim-pinia.d.ts

// TODO: https://github.com/vuejs/pinia/issues/2098
declare module 'pinia' {
  // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types
  export function acceptHMRUpdate(initialUseStore: StoreDefinition | any, hot: any): (newModule: any) => any;
}

export {}

3ddysan added a commit to 3ddysan/poka that referenced this issue Mar 29, 2023
- patch @vue/tsconfig for typescript 5 compatibility
- pinia and typescript 5 type error: vuejs/pinia#2098
@posva posva added bug Something isn't working contribution welcome typescript This issue is related to typings has workaround The issue contains a temporary solution to get around the problem labels Apr 3, 2023
@posva
Copy link
Member

posva commented Apr 3, 2023

Using as any for this particular case is fine. I will take a look in the future (I will remove the contribution welcome tag if I do) but feel free to take this if you want.

jaap3 added a commit to jaap3/pti-tools that referenced this issue Apr 16, 2023
posva added a commit that referenced this issue Apr 20, 2023
Co-authored-by: kalvens <kalvens@rtvision.com>
arnoson pushed a commit to miwos/app that referenced this issue May 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working contribution welcome has workaround The issue contains a temporary solution to get around the problem typescript This issue is related to typings
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants