瀏覽代碼

chore: Merge branch 'main' into minor

Evan You 2 年之前
父節點
當前提交
cda74beceb

+ 1 - 1
.github/workflows/autofix.yml

@@ -30,4 +30,4 @@ jobs:
       - name: Run prettier
         run: pnpm run format
 
-      - uses: autofix-ci/action@bee19d72e71787c12ca0f29de72f2833e437e4c9
+      - uses: autofix-ci/action@ea32e3a12414e6d3183163c3424a7d7a8631ad84

+ 7 - 1
packages/dts-test/ref.test-d.ts

@@ -244,13 +244,19 @@ expectType<typeof r1>(p1)
 // proxyRefs: `ShallowUnwrapRef`
 const r2 = {
   a: ref(1),
+  c: computed(() => 1),
+  u: undefined,
   obj: {
     k: ref('foo')
-  }
+  },
+  union: Math.random() > 0 - 5 ? ref({ name: 'yo' }) : null
 }
 const p2 = proxyRefs(r2)
 expectType<number>(p2.a)
+expectType<number>(p2.c)
+expectType<undefined>(p2.u)
 expectType<Ref<string>>(p2.obj.k)
+expectType<{ name: string } | null>(p2.union)
 
 // toRef and toRefs
 {

+ 3 - 7
packages/reactivity/src/ref.ts

@@ -490,15 +490,11 @@ type BaseTypes = string | number | boolean
 export interface RefUnwrapBailTypes {}
 
 export type ShallowUnwrapRef<T> = {
-  [K in keyof T]: T[K] extends Ref<infer V>
-    ? V // if `V` is `unknown` that means it does not extend `Ref` and is undefined
-    : T[K] extends Ref<infer V> | undefined
-      ? unknown extends V
-        ? undefined
-        : V | undefined
-      : T[K]
+  [K in keyof T]: DistrubuteRef<T[K]>
 }
 
+type DistrubuteRef<T> = T extends Ref<infer V> ? V : T
+
 export type UnwrapRef<T> = T extends ShallowRef<infer V>
   ? V
   : T extends Ref<infer V>

+ 1 - 1
packages/sfc-playground/package.json

@@ -13,7 +13,7 @@
     "vite": "^5.0.5"
   },
   "dependencies": {
-    "@vue/repl": "^3.0.0",
+    "@vue/repl": "^3.1.0",
     "file-saver": "^2.0.5",
     "jszip": "^3.10.1",
     "vue": "workspace:*"

+ 4 - 4
pnpm-lock.yaml

@@ -341,8 +341,8 @@ importers:
   packages/sfc-playground:
     dependencies:
       '@vue/repl':
-        specifier: ^3.0.0
-        version: 3.0.0
+        specifier: ^3.1.0
+        version: 3.1.0
       file-saver:
         specifier: ^2.0.5
         version: 2.0.5
@@ -1788,8 +1788,8 @@ packages:
     engines: {node: '>= 0.12.0'}
     dev: true
 
-  /@vue/repl@3.0.0:
-    resolution: {integrity: sha512-tGYibiftMo5yEuIKPWVsNuuNDejjJk0JQmvKtTm12KNLFqtGD7fWoGv1qUzcN9EAxwVeDgnT9ljRgqGVgZkyEg==}
+  /@vue/repl@3.1.0:
+    resolution: {integrity: sha512-lnR010NTkysg71Z0TVsFCTfiF5ARZbyohqymGpOxOrSuSI4o9RlSvWH6YmJdv9OHm5j69HKLVVUhXlCScMCQrg==}
     dev: false
 
   /@zeit/schemas@2.29.0: