fix(types): keep the original type when unwrapping markRaw (#3791)
This commit is contained in:
@@ -11,7 +11,7 @@ import {
|
||||
shallowCollectionHandlers,
|
||||
shallowReadonlyCollectionHandlers
|
||||
} from './collectionHandlers'
|
||||
import { UnwrapRefSimple, Ref } from './ref'
|
||||
import { UnwrapRefSimple, Ref, RawSymbol } from './ref'
|
||||
|
||||
export const enum ReactiveFlags {
|
||||
SKIP = '__v_skip',
|
||||
@@ -241,7 +241,9 @@ export function toRaw<T>(observed: T): T {
|
||||
return raw ? toRaw(raw) : observed
|
||||
}
|
||||
|
||||
export function markRaw<T extends object>(value: T): T {
|
||||
export function markRaw<T extends object>(
|
||||
value: T
|
||||
): T & { [RawSymbol]?: true } {
|
||||
def(value, ReactiveFlags.SKIP, true)
|
||||
return value
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import { CollectionTypes } from './collectionHandlers'
|
||||
import { createDep, Dep } from './dep'
|
||||
|
||||
declare const RefSymbol: unique symbol
|
||||
export declare const RawSymbol: unique symbol
|
||||
|
||||
export interface Ref<T = any> {
|
||||
value: T
|
||||
@@ -291,6 +292,7 @@ export type UnwrapRefSimple<T> = T extends
|
||||
| BaseTypes
|
||||
| Ref
|
||||
| RefUnwrapBailTypes[keyof RefUnwrapBailTypes]
|
||||
| { [RawSymbol]?: true }
|
||||
? T
|
||||
: T extends Array<any>
|
||||
? { [K in keyof T]: UnwrapRefSimple<T[K]> }
|
||||
|
||||
Reference in New Issue
Block a user