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

Missing UnwrapRef export #247

Closed
spaceemotion opened this issue Feb 11, 2020 · 6 comments
Closed

Missing UnwrapRef export #247

spaceemotion opened this issue Feb 11, 2020 · 6 comments
Labels
has PR misalignment Misalign with the latest RFC

Comments

@spaceemotion
Copy link

spaceemotion commented Feb 11, 2020

I wanted to switch a couple fields that belong together from individual ref()'s to a single reactive(). Since I am using TypeScript, I tried to import the UnwrapRef type, but instead of using the main import, it redirected me to its full path instead:

I can import this:

import { Ref } from '@vue/composition-api';

but need to do this for UnwrapRef:

import { UnwrapRef } from '@vue/composition-api/dist/reactivity/index.d';

has this been an oversight, or is there a reason (like, "probably don't want to use reactive at all")?

Edit: I also noticed that Refs seems to be missing?

@LinusBorg
Copy link
Member

I'm no sure why you'd need that type.

@pikax
Copy link
Member

pikax commented Feb 18, 2020

Having it exported, would allow it use that instead of declaring it again, for example, I'm building an library with composables, and sometime I need to access to wrap/unwrap.

On my case I described the types:
https://github.com/pikax/vue-composable/blob/4613b2703d67a40005dcc12230303e74ac48caf0/packages/core/src/utils.ts#L6-L20

export type UnwrapType<T> = T extends Ref<infer R> ? R : T;
export type WrapType<T> = T extends Ref<any> ? T : Ref<T>;

export function unwrap(o: RefElement): Element;
export function unwrap<T>(o: RefTyped<T>): T;
export function unwrap<T>(o: RefTyped<T>): T {
 return isRef(o) ? o.value : o;
}

export function wrap(o: RefElement): Ref<Element>;
export function wrap<T>(o: RefTyped<T>): Ref<T>;
export function wrap<T>(o: RefTyped<T>): Ref<T> {
 return isRef(o) ? o : ref(o);
}

EDIT: @vue/runtime-core exports UnwrapRef

EDIT2: There's a few functions not exported in this plugin, but exported on the vue-next, other example isReactive @vue/reactivity exports

@spaceemotion
Copy link
Author

In my case I would like to use a reactive object (with isLoading, data and error), but because the type information is missing, I had to fall back to individual refs().

@pikax
Copy link
Member

pikax commented Feb 25, 2020

@spaceemotion what do you mean? can you provide an example of how you would expect it to happen?

@antfu
Copy link
Member

antfu commented May 31, 2020

This seems to be covered in #311

@antfu antfu added has PR misalignment Misalign with the latest RFC labels May 31, 2020
@LinusBorg
Copy link
Member

Yes we can close it once #311 is merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has PR misalignment Misalign with the latest RFC
Projects
None yet
Development

No branches or pull requests

4 participants