posva / pinia-plugin-debounce

Config-based action debouncing made easy
MIT License
67 stars 3 forks source link

Types broken with resolutionMode node (node10) #114

Closed d-koppenhagen closed 11 months ago

d-koppenhagen commented 11 months ago

After updating to version 1.0.0, I get an error in my main.ts when importing the plugin:

Cannot find module '@pinia/plugin-debounce' or its corresponding type declarations.ts(2307)

Building the app works, but it seems the typings are not correct anymore.

d-koppenhagen commented 11 months ago

I was able to dig a bit deeper into it. It ssems only to be a problem when using a pinia options store. I cchanged my store to be a setup store and with this, types are correct.

lukashroch commented 11 months ago

Having similar issues after upgrade from 0.1.0 to 1.0.0.

Tried putting together our stripped repro to illustrate our use case: https://github.com/lukashroch/pinia-debounce-debug

https://github.com/lukashroch/pinia-debounce-debug/blob/main/packages/ui/src/stores/bootstrap.ts getting error in import

Cannot find module '@pinia/plugin-debounce' or its corresponding type declarations.

https://github.com/lukashroch/pinia-debounce-debug/blob/main/packages/ui/src/stores/app.ts and on store getting overload type error

No overload matches this call.
  Overload 1 of 3, '(id: "app", options: Omit<DefineStoreOptions<"app", AppState, {}, { doSomething(): void; }>, "id">): StoreDefinition<"app", AppState, {}, { ...; }>', gave the following error.
    Object literal may only specify known properties, and 'debounce' does not exist in type 'Omit<DefineStoreOptions<"app", AppState, {}, { doSomething(): void; }>, "id">'.
  Overload 2 of 3, '(id: "app", storeSetup: () => unknown, options?: DefineSetupStoreOptions<"app", _UnwrapAll<Pick<unknown, never>>, Pick<unknown, never>, Pick<unknown, never>> | undefined): StoreDefinition<...>', gave the following error.
    Object literal may only specify known properties, and 'state' does not exist in type '() => unknown'.ts(2769)

We have a monorepo with top-level vue3 and some apps/packages on vue2.7 in packages. I wonder if it's related to that. This works fine if reverted to 0.1.0 though.

posva commented 11 months ago

Are you by any chance using the node10 resolution mode? (https://arethetypeswrong.github.io/?p=%40pinia%2Fplugin-debounce%401.0.0)

lukashroch commented 11 months ago

@posva thanks, that was it! We still have node in some parts (which is effectively node10) due to backend code, but was able to isolate front and back and it works now with bundler.

posva commented 11 months ago

I updated the changelog to reflect that. It should be fine for all users to upgrade

lukashroch commented 11 months ago

@posva thanks! Unfortunately just found out that rest of the ecosystem doesn't play nice with "bundler" yet, e.g. global augmentation types for e.g. vue-router or vue-i18n (vue2.7 versions) are broken, so $route or $t are not visible and getting type errors, but starts to work if reverted to node resolution :-/

Property '$route' does not exist on type 'CreateComponentPublicInstance<{}, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin>'
posva commented 11 months ago

I see. Normally, it should be possible to fix the types to still be compatible with node 10. I clearly broke something while upgrading tsup and others. Feel free to give this a try, I don't have the bandwidth at the moment to fix it.