Explorar el Código

fix(types): relax the return type of props default option (#8537)

katashin hace 7 años
padre
commit
a9eb198413
Se han modificado 2 ficheros con 13 adiciones y 1 borrados
  1. 1 1
      types/options.d.ts
  2. 12 0
      types/test/options-test.ts

+ 1 - 1
types/options.d.ts

@@ -133,7 +133,7 @@ export type PropValidator<T> = PropOptions<T> | Prop<T> | Prop<T>[];
 export interface PropOptions<T=any> {
   type?: Prop<T> | Prop<T>[];
   required?: boolean;
-  default?: T | null | undefined | (() => object);
+  default?: T | null | undefined | (() => T | null | undefined);
   validator?(value: T): boolean;
 }
 

+ 12 - 0
types/test/options-test.ts

@@ -79,6 +79,18 @@ Vue.component('union-prop', {
   }
 });
 
+Vue.component('prop-with-primitive-default', {
+  props: {
+    id: {
+      type: String,
+      default: () => String(Math.round(Math.random() * 10000000))
+    }
+  },
+  created() {
+    this.id;
+  }
+});
+
 Vue.component('component', {
   data() {
     this.$mount