`useTimeout`: Support `MaybeRefOrGetter` argument type
Heniker opened this issue · comments
Clear and concise description of the problem
useTimeout
is the only function that uses number
as it's interval argument. useTimeoutPoll
, useInterval
, useTimeoutFn
all support specifying MaybeRefOrGetter
type.
Suggested solution
Change number
type to MaybeRefOrGetter<number>
Alternative
No response
Additional context
https://vueuse.org/shared/useTimeout
https://github.com/vueuse/vueuse/blob/main/packages/shared/useTimeout/index.ts
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
In my opinion, if we pass a variable of type MaybeRefOrGetter as an argument to a composable, one can expect that if the value changes, the composable will react to those changes, but in fact, it won't - the interval won't be changed. That's why I think it is better to have a number type for that.
The following code will work correctly ATM, aside from TS error:
const t = ref(1000);
const { ready, start, stop } = useTimeout(t, { controls: true });
console.log(ready.value); // false
await promiseTimeout(1100);
console.log(ready.value); // true
t.value = 2000;
start();
await promiseTimeout(1100);
console.log(ready.value); // false
await promiseTimeout(1100);
console.log(ready.value); // true
This is expected and reasonable behavior.
My point is not about reactivity - it's about inconsistency with other functions. I can't see why it requires any justification.