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
Argument of type 'Ref<null>' is not assignable to parameter of type 'MaybeElementRef<MaybeElement>'. #3240
Comments
The problem is solved, but I still want to know, how did this type of problem cause it? Is it just TypeScript Type Gymnastics? 😂 How can I avoid these kinds of problems? 🤔️ Everyone's tsconfig.json is different, can the official website provide a standard typescript development example? Thank you. import { onClickOutside } from '@vueuse/core';
import type { MaybeElement, MaybeElementRef } from '@vueuse/core';
const target = ref(null);
onClickOutside(target as unknown as MaybeElementRef<MaybeElement>, () => {
isShowCandidate.value = false;
});
return () => (
<div ref={target}></div>
); |
@rich1e How? I don't count this much has a solution.
|
I'm seeing this issue too when trying to upgrade my library to vue 3.3. import { ref } from 'vue';
import { useScroll } from '@vueuse/core';
const target = ref<HTMLDivElement | HTMLPreElement>();
const { x, y } = useScroll(target);
// ^^^^^^
// error TS2345:
// Argument of type 'Ref<HTMLDivElement | HTMLPreElement | undefined>' is not assignable to parameter of type 'MaybeRefOrGetter<HTMLElement | Window | Document | SVGElement | null | undefined>'.
// Property '[RefSymbol]' is missing in type 'Ref<HTMLDivElement | HTMLPreElement | undefined>' but required in type 'Ref<HTMLElement | Window | Document | SVGElement | null | undefined>'.
import { ref } from 'vue';
import { useFocusTrap } from '@vueuse/integrations/useFocusTrap';
const portal = ref<HTMLElement>();
useFocusTrap(portal, { immediate: true, escapeDeactivates: false });
// ^^^^^^
// error TS2345:
// Argument of type 'Ref<HTMLElement | undefined>' is not assignable to parameter of type 'MaybeElementRef'.
// Property '[RefSymbol]' is missing in type 'Ref<HTMLElement | undefined>' but required in type 'Ref<MaybeElement>'.
import { computed } from 'vue';
import { useMediaQuery } from '@vueuse/core';
import type { ComputedRef } from 'vue';
const computedQuery = (/*...*/): ComputedRef<string> => computed(() => { /*...*/ });
useMediaQuery(computedQuery(name, 'max'));
// ^^^^^^^^^^^^^^^^^^^^^^^^^^
// error TS2345:
// Argument of type 'ComputedRef<string>' is not assignable to parameter of type 'MaybeRefOrGetter<string>'.
// Property '[RefSymbol]' is missing in type 'ComputedRef<string>' but required in type 'Ref<string>'. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
I think it should be necessary to clarify this question, because I am not the only one who has questions. |
This is an issue I've been facing when I'm creating modules with Nuxt 3.8.*. I initially thought it was a tsserver issue, but it happens to be a problem with the types for VueUse, because replacing the type with Vue's native |
I arrived here after experiencing this issue today with EDIT: The issue is not resolved for me. Restarting the environment removes the error temporarily, but any other changes to the file restore it. The only solution that seems to work is the ugly type assertion conversion. |
Has anyone found a better workaround than the unknown hack? Still an issue with the latest version |
I found that blowing away the |
Has any solution ? I have met this problem for a long time . I just used @ts-ignore when in my project |
Resolves issue vueuse/vueuse#3240
This continues to be an issue:
Some errors I'm seeing:
|
Describe the bug
What is the cause of this problem? How to solve it?
code
package.json
Ref
Solved without doing anything? #405
Reproduction
https://stackblitz.com/
System Info
Used Package Manager
pnpm
Validations
The text was updated successfully, but these errors were encountered: