diff --git a/packages/reactivity/src/ref.ts b/packages/reactivity/src/ref.ts index b4127c113..10e577fe5 100644 --- a/packages/reactivity/src/ref.ts +++ b/packages/reactivity/src/ref.ts @@ -85,6 +85,11 @@ function toProxyRef( type UnwrapArray = { [P in keyof T]: UnwrapRef } +// corner case when use narrows type +// Ex. type RelativePath = string & { __brand: unknown } +// RelativePath extends object -> true +type BaseTypes = string | number | boolean + // Recursively unwraps nested value bindings. export type UnwrapRef = { cRef: T extends ComputedRef ? UnwrapRef : T @@ -97,6 +102,6 @@ export type UnwrapRef = { ? 'ref' : T extends Array ? 'array' - : T extends Function | CollectionTypes + : T extends Function | CollectionTypes | BaseTypes ? 'ref' // bail out on types that shouldn't be unwrapped : T extends object ? 'object' : 'ref'] diff --git a/test-dts/defineComponent.test-d.tsx b/test-dts/defineComponent.test-d.tsx index 3cde7426e..a6393dd15 100644 --- a/test-dts/defineComponent.test-d.tsx +++ b/test-dts/defineComponent.test-d.tsx @@ -12,6 +12,8 @@ describe('with object props', () => { ddd: string[] } + type GT = string & { __brand: unknown } + const MyComponent = defineComponent({ props: { a: Number, @@ -57,6 +59,9 @@ describe('with object props', () => { c: ref(1), d: { e: ref('hi') + }, + f: { + g: ref('hello' as GT) } } }, @@ -88,6 +93,7 @@ describe('with object props', () => { // assert setup context unwrapping expectType(this.c) expectType(this.d.e) + expectType(this.f.g) // setup context properties should be mutable this.c = 2