chore: comments regarding Readonly usage

This commit is contained in:
Evan You 2019-11-02 10:40:08 -04:00
parent 26c859aedd
commit abdaf10d88
2 changed files with 5 additions and 0 deletions

View File

@ -68,6 +68,8 @@ export function createComponent<
// overload 4: object format with object props declaration // overload 4: object format with object props declaration
// see `ExtractPropTypes` in ./componentProps.ts // see `ExtractPropTypes` in ./componentProps.ts
export function createComponent< export function createComponent<
// the Readonly constraint allows TS to treat the type of { required: true }
// as constant instead of boolean.
PropsOptions extends Readonly<ComponentPropsOptions>, PropsOptions extends Readonly<ComponentPropsOptions>,
RawBindings, RawBindings,
D, D,

View File

@ -68,6 +68,9 @@ export function watch<T>(
): StopHandle ): StopHandle
// overload #3: array of multiple sources + cb // 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>[]>>( export function watch<T extends Readonly<WatcherSource<unknown>[]>>(
sources: T, sources: T,
cb: WatchHandler<MapSources<T>>, cb: WatchHandler<MapSources<T>>,