]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
chore: comments regarding Readonly usage
authorEvan You <yyx990803@gmail.com>
Sat, 2 Nov 2019 14:40:08 +0000 (10:40 -0400)
committerEvan You <yyx990803@gmail.com>
Sat, 2 Nov 2019 14:40:08 +0000 (10:40 -0400)
packages/runtime-core/src/apiCreateComponent.ts
packages/runtime-core/src/apiWatch.ts

index c1503278ee0a4a7b02a264588e0fac4c4f45584a..f4ab9bd3792260b5eefa9b6b2a1eada7cfaf0e7f 100644 (file)
@@ -68,6 +68,8 @@ export function createComponent<
 // overload 4: object format with object props declaration
 // see `ExtractPropTypes` in ./componentProps.ts
 export function createComponent<
+  // the Readonly constraint allows TS to treat the type of { required: true }
+  // as constant instead of boolean.
   PropsOptions extends Readonly<ComponentPropsOptions>,
   RawBindings,
   D,
index 9f530661b29adeffe5ab222d806e90849d89ddc1..8abe22ee93dfb152b0a5d976be518132f483c0ca 100644 (file)
@@ -68,6 +68,9 @@ export function watch<T>(
 ): StopHandle
 
 // overload #3: array of multiple sources + cb
+// Readonly constraint helps the callback to correctly infer value types based
+// on position in the source array. Otherwise the values will get a union type
+// of all possible value types.
 export function watch<T extends Readonly<WatcherSource<unknown>[]>>(
   sources: T,
   cb: WatchHandler<MapSources<T>>,