From bc1f097e29c5c823737503532baa23c11d4824f8 Mon Sep 17 00:00:00 2001 From: Evan You Date: Mon, 4 May 2020 08:51:01 -0400 Subject: [PATCH] fix(types/reactivity): fix ref type inference on nested reactive properties with .value fix #1111 --- packages/reactivity/src/ref.ts | 8 ++++++-- test-dts/ref.test-d.ts | 11 ++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/packages/reactivity/src/ref.ts b/packages/reactivity/src/ref.ts index 629a2dad..dc446974 100644 --- a/packages/reactivity/src/ref.ts +++ b/packages/reactivity/src/ref.ts @@ -5,11 +5,15 @@ import { reactive, isProxy, toRaw } from './reactive' import { ComputedRef } from './computed' import { CollectionTypes } from './collectionHandlers' +const RefSymbol = Symbol() + export interface Ref { /** - * @internal + * Type differentiator only. + * We need this to be in public d.ts but don't want it to show up in IDE + * autocomplete, so we use a private Symbol instead. */ - __v_isRef: true + [RefSymbol]: true value: T } diff --git a/test-dts/ref.test-d.ts b/test-dts/ref.test-d.ts index 41dc6ee7..e2454e03 100644 --- a/test-dts/ref.test-d.ts +++ b/test-dts/ref.test-d.ts @@ -1,5 +1,5 @@ import { expectType } from 'tsd' -import { Ref, ref, isRef, unref } from './index' +import { Ref, ref, isRef, unref, reactive } from './index' function plainType(arg: number | Ref) { // ref coercing @@ -84,3 +84,12 @@ function withSymbol() { } withSymbol() + +const state = reactive({ + foo: { + value: 1, + label: 'bar' + } +}) + +expectType(state.foo.label)