vueuse / vue-demi

🎩 Creates Universal Library for Vue 2 & 3
MIT License
2.9k stars 149 forks source link

Re-export Options API needed type #245

Open Glandos opened 10 months ago

Glandos commented 10 months ago

fix https://github.com/vueuse/vueuse/issues/2232

Please adjust if importing from v3-generated is a bad practice, but the ticket has been opened for too long, and stale-bot is a bit too fast.

antfu commented 10 months ago

Maybe you could propose exporting it to the main entry of Vue 3 directly?

Glandos commented 10 months ago

After a deeper look, I found this fix to be… not adequate. The issue comes from the fact that vueused/shared references WatchOptions['flush']. However, this flush member doesn't exist in Vue 2. So it should be redefined in vue-demi as an augmented interface, with type never, as in:

declare vue {
    interface WatchOptions {
        flush: never
    }
}

Or something similar. However, the referenced stackblitz also give the following output when running npx vue-tsc:

node_modules/@vueuse/shared/index.d.ts:955:196 - error TS2315: Type 'WatchOptions' is not generic.

955 declare function watchArray<T, Immediate extends Readonly<boolean> = false>(source: WatchSource<T[]> | T[], cb: WatchArrayCallback<T[], Immediate extends true ? T[] | undefined : T[]>, options?: WatchOptions<Immediate>): vue_demi.WatchStopHandle;

The error is repeated multiple times, but the cause is the same: the interface is not generic. And I don't see a way to make it work reliably with a generic…