-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[reactivity][type] createReactiveEffect() and effect() have difference between static type and runtime #3647
Comments
Please double-check the reproduction you provided, it cannot reproduce the problem you described. |
export function effect<T = any>(
fn: () => T,
options: ReactiveEffectOptions = EMPTY_OBJ
): ReactiveEffect<T> {
if (isEffect(fn)) {
fn = fn.raw
}
const effect = createReactiveEffect(fn, options)
if (!options.lazy) {
effect()
}
return effect
} example for const re2 = effect(() => 1, {
scheduler: window.setImmediate
}) What is expected?
What is actually happening?
|
some type programing maybe helpful. I guess this need tests and .d.ts tests, which I don't know how to do it and can't send PR to fix it. export function effect<T = any, O extends ReactiveEffectOptions = typeof EMPTY_OBJ>(
fn: () => T,
options: O = (EMPTY_OBJ as O)
): O extends { scheduler?: undefined } ? ReactiveEffect<T> : ReactiveEffect<T | undefined> {
type Returned = O extends { scheduler?: undefined } ? ReactiveEffect<T> : ReactiveEffect<T | undefined>
if (isEffect(fn)) {
fn = fn.raw
}
const effect = createReactiveEffect(fn, options)
if (!options.lazy) {
effect()
}
return effect as Returned
}
const a = effect(() => 1) // => ReactiveEffect<number >
const a2 = effect(() => 1, { scheduler: setImmediate }) // => ReactiveEffect<number | undefined> |
I get your points now, but it will return |
doesn't have the problem after commit 03a7a73 |
Version
3.0.11
Reproduction link
https://codesandbox.io/s/elegant-chandrasekhar-dlmc4?file=/src/main.js
Steps to reproduce
for
but for
What is expected?
What is actually happening?
Please correct me if I am wrong
The text was updated successfully, but these errors were encountered: