UNPKG

idx

Version:

Utility function for traversing properties on objects and arrays.

41 lines (35 loc) 1.22 kB
/** * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * * @flow strict */ declare opaque type DeepRequiredArray<+T>: $ReadOnlyArray< DeepRequired<$NonMaybeType<T>>, >; declare opaque type DeepRequiredObject<+T: interface {}>: Required<{ +[K in keyof T]: DeepRequired<T[K]>, }>; declare opaque type DeepRequired<T>: T extends empty ? $FlowFixMe // If something can pass empty, it's already unsafe : T extends $ReadOnlyArray<infer V> ? DeepRequiredArray<V> : T extends (...$ReadOnlyArray<empty>) => mixed ? T : T extends interface {} ? DeepRequiredObject<T> : $NonMaybeType<T>; type UnboxDeepRequired<T> = T extends DeepRequired<infer V> ? V : T; /** * @see https://github.com/facebook/idx * * If you entered the file with the hope to understand why something doesn't * type check, you should stop, and migrate your code away from idx first. * idx is deprecated, and you should always use optional chaining instead. */ declare module.exports: <T1, T2>( prop: T1, accessor: (prop: $NonMaybeType<DeepRequired<T1>>) => T2, ) => ?UnboxDeepRequired<T2>;