Skip to content

Typing the return of toRefs #315

@absolutejam

Description

@absolutejam

Howdy,

First of all, I just want to say how much I enjoy using Vue and the new composition api is amazing. Great job 👍

I'm using Typescript in my project and I've generally been using pretty basic interfaces and inference where possible, but I hit a problem yesterday wherein the return type of toRefs() wasn't valid.

I spent quite a while poking around in the composition-api source, inspecting type definitions, and eventually I realised that I could create the following type which will wrap an existing type/interface's properties in Ref.

type Refs<T> = {
  [P in keyof T]: Ref<T[P]>;
};

But I couldn't see something available/documented to provide this. Is this something that should be part of the library or would people be expected to provide something themselves?

Regards,
James.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions