-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(experimental): expose ref macro types using separate d.ts file
- Loading branch information
Showing
5 changed files
with
97 additions
and
94 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { | ||
Ref, | ||
UnwrapRef, | ||
ComputedRef, | ||
WritableComputedOptions, | ||
DebuggerOptions, | ||
WritableComputedRef, | ||
ShallowUnwrapRef | ||
} from '@vue/runtime-dom' | ||
|
||
declare const RefMarker: unique symbol | ||
type RefValue<T> = T & { [RefMarker]?: any } | ||
|
||
declare const ComputedRefMarker: unique symbol | ||
type ComputedRefValue<T> = T & { [ComputedRefMarker]?: any } | ||
|
||
declare const WritableComputedRefMarker: unique symbol | ||
type WritableComputedRefValue<T> = T & { [WritableComputedRefMarker]?: any } | ||
|
||
/** | ||
* Vue ref transform macro for binding refs as reactive variables. | ||
*/ | ||
declare function _$<T>(arg: ComputedRef<T>): ComputedRefValue<T> | ||
declare function _$<T>(arg: WritableComputedRef<T>): WritableComputedRefValue<T> | ||
declare function _$<T>(arg: Ref<T>): RefValue<T> | ||
declare function _$<T extends object>(arg?: T): ShallowUnwrapRef<T> | ||
|
||
/** | ||
* Vue ref transform macro for accessing underlying refs of reactive varaibles. | ||
*/ | ||
declare function _$$<T>(value: T): ComputedRef<T> | ||
declare function _$$<T>( | ||
value: WritableComputedRefValue<T> | ||
): WritableComputedRef<T> | ||
declare function _$$<T>(value: RefValue<T>): Ref<T> | ||
declare function _$$<T extends object>(arg: T): ToRawRefs<T> | ||
|
||
type ToRawRefs<T extends object> = { | ||
[K in keyof T]: T[K] extends ComputedRefValue<infer V> | ||
? ComputedRefValue<V> | ||
: T[K] extends WritableComputedRefValue<infer V> | ||
? WritableComputedRef<V> | ||
: T[K] extends RefValue<infer V> | ||
? Ref<V> | ||
: T[K] extends object | ||
? T[K] extends | ||
| Function | ||
| Map<any, any> | ||
| Set<any> | ||
| WeakMap<any, any> | ||
| WeakSet<any> | ||
? T[K] | ||
: ToRawRefs<T[K]> | ||
: T[K] | ||
} | ||
|
||
declare function _$ref<T>(arg?: T | Ref<T>): RefValue<UnwrapRef<T>> | ||
|
||
declare function _$shallowRef<T>(arg?: T): RefValue<T> | ||
|
||
declare function _$computed<T>( | ||
getter: () => T, | ||
debuggerOptions?: DebuggerOptions | ||
): ComputedRefValue<T> | ||
declare function _$computed<T>( | ||
options: WritableComputedOptions<T>, | ||
debuggerOptions?: DebuggerOptions | ||
): WritableComputedRefValue<T> | ||
|
||
declare global { | ||
const $: typeof _$ | ||
const $$: typeof _$$ | ||
const $ref: typeof _$ref | ||
const $shallowRef: typeof _$shallowRef | ||
const $computed: typeof _$computed | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters