From: Evan You Date: Sat, 2 Nov 2019 14:40:08 +0000 (-0400) Subject: chore: comments regarding Readonly usage X-Git-Tag: v3.0.0-alpha.0~257 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=abdaf10d8805e3dab62b65dcc88b25090e660279;p=thirdparty%2Fvuejs%2Fcore.git chore: comments regarding Readonly usage --- diff --git a/packages/runtime-core/src/apiCreateComponent.ts b/packages/runtime-core/src/apiCreateComponent.ts index c1503278ee..f4ab9bd379 100644 --- a/packages/runtime-core/src/apiCreateComponent.ts +++ b/packages/runtime-core/src/apiCreateComponent.ts @@ -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, RawBindings, D, diff --git a/packages/runtime-core/src/apiWatch.ts b/packages/runtime-core/src/apiWatch.ts index 9f530661b2..8abe22ee93 100644 --- a/packages/runtime-core/src/apiWatch.ts +++ b/packages/runtime-core/src/apiWatch.ts @@ -68,6 +68,9 @@ export function watch( ): 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[]>>( sources: T, cb: WatchHandler>,