Skip to content

Typescript errors with pinia 0.5.1 #504

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

Closed
bcronje opened this issue May 20, 2021 · 3 comments
Closed

Typescript errors with pinia 0.5.1 #504

bcronje opened this issue May 20, 2021 · 3 comments
Labels
need repro This issue couldn't be reproduced

Comments

@bcronje
Copy link

bcronje commented May 20, 2021

Reproduction

Create a new Vue 2 project with typescript support using Vue CLI. Install pinia and composition api npm install pinia @vue/composition-api and set skipLibCheck in tsconfig.json to false e.g. "skipLibCheck": false

Run npm run serve

Expected behavior

Expected project to compile without any typescript errors.

Actual behavior

Got the following errors:

ERROR in D:/Temp/test/testvue/node_modules/pinia/dist/src/types.d.ts(143,108):
143:108 Type 'Record<string, (() => any) | ((state: UnwrapRef<S & PiniaCustomStateProperties<S>>) => any)>' does not satisfy the constraint 'Record<string, (() => any) | ((state: { [x: string]: any; [x: number]: any; }) => any)>'.
  Index signatures are incompatible.
    Type '(() => any) | ((state: UnwrapRef<S & PiniaCustomStateProperties<S>>) => any)' is not assignable to type '(() => any) | ((state: { [x: string]: any; [x: number]: any; }) => any)'.
      Type '(state: UnwrapRef<S & PiniaCustomStateProperties<S>>) => any' is not assignable to type '(() => any) | ((state: { [x: string]: any; [x: number]: any; }) => any)'.
        Type '(state: UnwrapRef<S & PiniaCustomStateProperties<S>>) => any' is not assignable to type '() => any'.
    141 |  * @internal
    142 |  */
  > 143 | export interface StoreWithState<Id extends string, S extends StateTree, G extends GettersTree<StateTree> = GettersTree<S>, A = ActionsTree> {
        |                                                                                                            ^
    144 |     /**
    145 |      * Unique identifier of the store
    146 |      */
ERROR in D:/Temp/test/testvue/node_modules/pinia/dist/src/types.d.ts(253,199):
253:199 Type 'G' does not satisfy the constraint 'Record<string, (() => any) | ((state: { [x: string]: any; [x: number]: any; }) => any)>'.
  Type 'Record<string, (() => any) | ((state: UnwrapRef<S & PiniaCustomStateProperties<S>>) => any)>' is not assignable to type 'Record<string, (() => any) | ((state: { [x: string]: any; [x: number]: any; }) => any)>'. 
    Index signatures are incompatible.
      Type '(() => any) | ((state: UnwrapRef<S & PiniaCustomStateProperties<S>>) => any)' is not assignable to type '(() => any) | ((state: { [x: string]: any; [x: number]: any; }) => any)'.
        Type '(state: UnwrapRef<S & PiniaCustomStateProperties<S>>) => any' is not assignable to type '(() => any) | ((state: { [x: string]: any; [x: number]: any; }) => any)'.
          Type '(state: UnwrapRef<S & PiniaCustomStateProperties<S>>) => any' is not assignable to type '() => any'.
    251 |  * Store type to build a store
    252 |  */
  > 253 | export declare type Store<Id extends string = string, S extends StateTree = StateTree, G extends GettersTree<S> = GettersTree<S>, A = ActionsTree> = StoreWithState<Id, StateTree extends S ? {} : S, G, A> & (StateTree extends S ? {} : UnwrapRef<S>) & (GettersTree<S> extends G ? {} : StoreWithGetters<G>) & (ActionsTree extends A ? {} : StoreWithActions<A>) & PiniaCustomProperties<Id, S, G, A> & PiniaCustomStateProperties<S>;  
        |                                                                                                                                                                                                       ^
    254 | /**
    255 |  * Generic and type-unsafe version of Store. Doesn't fail on access with
    256 |  * strings, making it much easier to write generic functions that do not care
ERROR in D:/Temp/test/testvue/node_modules/pinia/dist/src/types.d.ts(259,179):
259:179 Type 'G' does not satisfy the constraint 'Record<string, (() => any) | ((state: { [x: string]: any; [x: number]: any; }) => any)>'.
  Type 'Record<string, (() => any) | ((state: UnwrapRef<S & PiniaCustomStateProperties<S>>) => any)>' is not assignable to type 'Record<string, (() => any) | ((state: { [x: string]: any; [x: number]: any; }) => any)>'. 
    Index signatures are incompatible.
      Type '(() => any) | ((state: UnwrapRef<S & PiniaCustomStateProperties<S>>) => any)' is not assignable to type '(() => any) | ((state: { [x: string]: any; [x: number]: any; }) => any)'.
        Type '(state: UnwrapRef<S & PiniaCustomStateProperties<S>>) => any' is not assignable to type '(() => any) | ((state: { [x: string]: any; [x: number]: any; }) => any)'.
          Type '(state: UnwrapRef<S & PiniaCustomStateProperties<S>>) => any' is not assignable to type '() => any'.
    257 |  * about the kind of store that is passed.
    258 |  */
  > 259 | export declare type GenericStore<Id extends string = string, S extends StateTree = StateTree, G extends GettersTree<S> = GettersTree<S>, A = ActionsTree> = StoreWithState<Id, S, G, A> & UnwrapRef<S> & StoreWithGetters<G> & StoreWithActions<A> & PiniaCustomProperties<Id, S, G, A> & PiniaCustomStateProperties<S>;
        |                                                                                                                                                                                   ^
    260 | /**
    261 |  * Return type of `defineStore()`. Function that allows instantiating a store.
    262 |  */
ERROR in D:/Temp/test/testvue/node_modules/pinia/dist/src/types.d.ts(315,69):
315:69 Type 'G' does not satisfy the constraint 'Record<string, (() => any) | ((state: { [x: string]: any; [x: number]: any; }) => any)>'.
  Type 'Record<string, (() => any) | ((state: UnwrapRef<S & PiniaCustomStateProperties<S>>) => any)>' is not assignable to type 'Record<string, (() => any) | ((state: { [x: string]: any; [x: number]: any; }) => any)>'. 
    Index signatures are incompatible.
      Type '(() => any) | ((state: UnwrapRef<S & PiniaCustomStateProperties<S>>) => any)' is not assignable to type '(() => any) | ((state: { [x: string]: any; [x: number]: any; }) => any)'.
        Type '(state: UnwrapRef<S & PiniaCustomStateProperties<S>>) => any' is not assignable to type '(() => any) | ((state: { [x: string]: any; [x: number]: any; }) => any)'.
          Type '(state: UnwrapRef<S & PiniaCustomStateProperties<S>>) => any' is not assignable to type '() => any'.
    313 |      * Optional object of actions.
    314 |      */
  > 315 |     actions?: A & ThisType<A & UnwrapRef<S> & StoreWithState<Id, S, G, A> & StoreWithGetters<G> & PiniaCustomProperties & PiniaCustomStateProperties>;
        |                                                                     ^
    316 | }
    317 | //# sourceMappingURL=types.d.ts.map
Version: typescript 4.1.5

Additional information

Using typescript 4.1.5
Dependencies:

"dependencies": {
    "@vue/composition-api": "^1.0.0-rc.9",
    "core-js": "^3.6.5",
    "pinia": "^0.5.1",
    "vue": "^2.6.11"
  }
@posva
Copy link
Member

posva commented May 20, 2021

I need a repro on GitHub to check

@posva posva added the need repro This issue couldn't be reproduced label May 20, 2021
@bcronje
Copy link
Author

bcronje commented May 20, 2021

Here you go https://github.com/bcronje/testpinia

Just a standard Vue CLI project with typescript enabled, pinia and composition API installed and with skipLibCheck in tsconfig.json set to false.

After cloning just run:

npm install
npm run serve

Produces the original type errors.

@posva
Copy link
Member

posva commented May 27, 2021

I see a different error which I'm aware of and reported microsoft/TypeScript#44295 and I will adapt pinia's code based if the change was intended.

As a workaround, use TS 4.2 or set skipLibCheck to true

@posva posva closed this as completed May 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need repro This issue couldn't be reproduced
Projects
None yet
Development

No branches or pull requests

2 participants