/opt/canhelp/node_modules/kysely/dist/cjs/util
Edit: /opt/canhelp/node_modules/kysely/dist/cjs/util/require-all-props.d.ts (1755B)
/**
* Utility type to force use of all properties of T.
*
* Similar to Required
build-in type, but allows `undefined` values.
*/
type AllProps = T & {
[P in keyof T]-?: unknown;
};
/**
* Helper function to check listed properties according to given type. Check if all properties has been used when object is initialised.
*
* Example use:
*
* ```ts
* type SomeType = { propA: string; propB?: number; }
*
* // propB has to be mentioned even it is optional. It still should be initialized with undefined.
* const a: SomeType = requireAllProps({ propA: "value A", propB: undefined });
*
* // checked type is implicit for variable.
* const b = requireAllProps({ propA: "value A", propB: undefined });
* ```
*
* Wrong use of this helper:
*
* 1. Omit checked type - all checked properties will be expect as of type never
*
* ```ts
* type SomeType = { propA: string; propB?: number; }
* // const z: SomeType = requireAllProps({ propC: "no type will work" }); // Property 'propA' is missing in type '{ propC: string; }' but required in type 'SomeType'.
* ```
*
* 2. Apply to spreaded object - there is no way how to check in compile time if spreaded object contains all properties
*
* ```ts
* type SomeType = { propA: string; propB?: number; }
* const y: SomeType = { propA: "" }; // valid object according to SomeType declaration
* // const x = requireAllProps({ ...y }); // Argument of type '{ propA: string; propB?: number; }' is not assignable to parameter of type 'AllProps'.
* ```
*
* @param obj object to check if all properties has been used
* @returns untouched obj parameter is returned
*/
export declare function requireAllProps(obj: AllProps): T;
export {};