Skip to content
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

useTimeout: Support MaybeRefOrGetter argument type #3894

Open
4 tasks done
Heniker opened this issue Mar 28, 2024 · 2 comments
Open
4 tasks done

useTimeout: Support MaybeRefOrGetter argument type #3894

Heniker opened this issue Mar 28, 2024 · 2 comments
Labels
enhancement New feature or request vue: upstream

Comments

@Heniker
Copy link

Heniker commented Mar 28, 2024

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

@Heniker Heniker added the enhancement New feature or request label Mar 28, 2024
@oleksandr-hyriavets
Copy link
Contributor

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.

@Heniker
Copy link
Author

Heniker commented Mar 28, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request vue: upstream
Projects
None yet
Development

No branches or pull requests

2 participants