Skip to content

Commit bc1f097

Browse files
committed
fix(types/reactivity): fix ref type inference on nested reactive properties with .value
fix #1111
1 parent f40f3a0 commit bc1f097

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

packages/reactivity/src/ref.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@ import { reactive, isProxy, toRaw } from './reactive'
55
import { ComputedRef } from './computed'
66
import { CollectionTypes } from './collectionHandlers'
77

8+
const RefSymbol = Symbol()
9+
810
export interface Ref<T = any> {
911
/**
10-
* @internal
12+
* Type differentiator only.
13+
* We need this to be in public d.ts but don't want it to show up in IDE
14+
* autocomplete, so we use a private Symbol instead.
1115
*/
12-
__v_isRef: true
16+
[RefSymbol]: true
1317
value: T
1418
}
1519

test-dts/ref.test-d.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expectType } from 'tsd'
2-
import { Ref, ref, isRef, unref } from './index'
2+
import { Ref, ref, isRef, unref, reactive } from './index'
33

44
function plainType(arg: number | Ref<number>) {
55
// ref coercing
@@ -84,3 +84,12 @@ function withSymbol() {
8484
}
8585

8686
withSymbol()
87+
88+
const state = reactive({
89+
foo: {
90+
value: 1,
91+
label: 'bar'
92+
}
93+
})
94+
95+
expectType<string>(state.foo.label)

0 commit comments

Comments
 (0)