Skip to content

Commit

Permalink
fix(types/reactivity): fix ref type inference on nested reactive prop…
Browse files Browse the repository at this point in the history
…erties with .value

fix #1111
  • Loading branch information
yyx990803 committed May 4, 2020
1 parent f40f3a0 commit bc1f097
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
8 changes: 6 additions & 2 deletions packages/reactivity/src/ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ import { reactive, isProxy, toRaw } from './reactive'
import { ComputedRef } from './computed'
import { CollectionTypes } from './collectionHandlers'

const RefSymbol = Symbol()

export interface Ref<T = any> {
/**
* @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
}

Expand Down
11 changes: 10 additions & 1 deletion test-dts/ref.test-d.ts
Original file line number Diff line number Diff line change
@@ -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<number>) {
// ref coercing
Expand Down Expand Up @@ -84,3 +84,12 @@ function withSymbol() {
}

withSymbol()

const state = reactive({
foo: {
value: 1,
label: 'bar'
}
})

expectType<string>(state.foo.label)

0 comments on commit bc1f097

Please sign in to comment.