Skip to content

Commit

Permalink
[code-infra] Add documentation to internal types
Browse files Browse the repository at this point in the history
  • Loading branch information
JCQuintas committed Nov 21, 2024
1 parent 9ebf586 commit aaeec44
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 17 deletions.
15 changes: 15 additions & 0 deletions packages/x-internals/src/types/DefaultizedProps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* Combines a type with required and additional properties.
*
* @template P - The original type.
* @template RequiredProps - The keys to make required.
* @template AdditionalProps - Additional properties to include.
*/

export type DefaultizedProps<
P extends {},
RequiredProps extends keyof P,
AdditionalProps extends {} = {},
> = Omit<P, RequiredProps | keyof AdditionalProps> &
Required<Pick<P, RequiredProps>> &
AdditionalProps;
7 changes: 7 additions & 0 deletions packages/x-internals/src/types/MakeOptional.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* Makes specified keys in a type optional.
*
* @template T - The original type.
* @template K - The keys to make optional.
*/
export type MakeOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
8 changes: 8 additions & 0 deletions packages/x-internals/src/types/MakeRequired.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* Makes specified keys in a type required.
*
* @template T - The original type.
* @template K - The keys to make required.
*/

export type MakeRequired<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
13 changes: 13 additions & 0 deletions packages/x-internals/src/types/SlotComponentPropsFromProps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* Defines the props for a slot component, which can be either partial props with overrides or a function returning such props.
*
* @template TProps - The original props type.
* @template TOverrides - The overrides type.
* @template TOwnerState - The owner state type.
*/

export type SlotComponentPropsFromProps<
TProps extends {},
TOverrides extends {},
TOwnerState extends {},
> = (Partial<TProps> & TOverrides) | ((ownerState: TOwnerState) => Partial<TProps> & TOverrides);
21 changes: 4 additions & 17 deletions packages/x-internals/src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,4 @@
export type MakeOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;

export type MakeRequired<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;

export type DefaultizedProps<
P extends {},
RequiredProps extends keyof P,
AdditionalProps extends {} = {},
> = Omit<P, RequiredProps | keyof AdditionalProps> &
Required<Pick<P, RequiredProps>> &
AdditionalProps;

export type SlotComponentPropsFromProps<
TProps extends {},
TOverrides extends {},
TOwnerState extends {},
> = (Partial<TProps> & TOverrides) | ((ownerState: TOwnerState) => Partial<TProps> & TOverrides);
export * from './DefaultizedProps';
export * from './MakeOptional';
export * from './MakeRequired';
export * from './SlotComponentPropsFromProps';

0 comments on commit aaeec44

Please sign in to comment.