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

types: making ComputedRef types inline with vue3 and provide ComputdRef type #310

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/apis/computed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,20 @@ interface Option<T> {
set: (value: T) => void;
}

export interface ComputedRef<T = any> extends WritableComputedRef<T> {
readonly value: T;
}

interface WritableComputedRef<T> extends Ref<T> {}

// read-only
export function computed<T>(getter: Option<T>['get']): Readonly<Ref<Readonly<T>>>;
export function computed<T>(getter: Option<T>['get']): ComputedRef<T>;
// writable
export function computed<T>(options: Option<T>): Ref<Readonly<T>>;
export function computed<T>(options: Option<T>): WritableComputedRef<T>;
// implement
export function computed<T>(
options: Option<T>['get'] | Option<T>
): Readonly<Ref<Readonly<T>>> | Ref<Readonly<T>> {
): ComputedRef<T> | WritableComputedRef<T> {
const vm = getCurrentVM();
let get: Option<T>['get'], set: Option<T>['set'] | undefined;
if (typeof options === 'function') {
Expand Down