vue-demi icon indicating copy to clipboard operation
vue-demi copied to clipboard

Re-export Options API needed type

Open Glandos opened this issue 2 years ago • 2 comments

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.

Glandos avatar Sep 20 '23 08:09 Glandos

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

antfu avatar Sep 20 '23 11:09 antfu

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…

Glandos avatar Sep 20 '23 12:09 Glandos