Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[types] Moved types from OverridableComponent.d.ts to @material-ui/types #23265

Closed
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions packages/material-ui-types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,73 @@ type IfEquals<T, U, Y = unknown, N = never> = (<G>() => G extends T ? 1 : 2) ext
* @param actual
*/
export function expectType<Expected, Actual>(actual: IfEquals<Actual, Expected, Actual>): void;

/**
* A component whose root component can be controlled via a `component` prop.
*
* Adjusts valid props based on the type of `component`.
*/
export interface OverridableComponent<M extends OverridableTypeMap> {
<C extends React.ElementType>(
props: {
/**
* The component used for the root node.
* Either a string to use a HTML element or a component.
*/
component: C;
} & OverrideProps<M, C>
): JSX.Element;
(props: DefaultComponentProps<M>): JSX.Element;
}

/**
* Props of the component if `component={Component}` is used.
*/
// prettier-ignore
export type OverrideProps<
M extends OverridableTypeMap,
C extends React.ElementType
> = (
& BaseProps<M>
& Omit<React.ComponentPropsWithRef<C>, keyof BaseProps<M>>
);

/**
* Props if `component={Component}` is NOT used.
*/
// prettier-ignore
export type DefaultComponentProps<M extends OverridableTypeMap> =
& BaseProps<M>
& Omit<React.ComponentPropsWithRef<M['defaultComponent']>, keyof BaseProps<M>>;

/**
* Props defined on the component (+ common material-ui props).
*/
// prettier-ignore
export type BaseProps<M extends OverridableTypeMap> =
& M['props']
& CommonProps;

/**
* Props that are valid for material-ui components.
*/
export interface CommonProps {
className?: string;
style?: React.CSSProperties;
}
mnajdova marked this conversation as resolved.
Show resolved Hide resolved

export interface OverridableTypeMap {
props: {};
defaultComponent: React.ElementType;
}

/**
* @deprecated Not used in this library.
*/
export type Simplify<T> = T extends any ? { [K in keyof T]: T[K] } : never;

/**
* @deprecated Not used in this library.
*/
// tslint:disable-next-line: deprecation
export type SimplifiedPropsOf<C extends React.ElementType> = Simplify<React.ComponentProps<C>>;
Comment on lines +135 to +144
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we remove it?

Suggested change
/**
* @deprecated Not used in this library.
*/
export type Simplify<T> = T extends any ? { [K in keyof T]: T[K] } : never;
/**
* @deprecated Not used in this library.
*/
// tslint:disable-next-line: deprecation
export type SimplifiedPropsOf<C extends React.ElementType> = Simplify<React.ComponentProps<C>>;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, please!

20 changes: 3 additions & 17 deletions packages/material-ui/src/OverridableComponent.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import * as React from 'react';
import { Omit } from '@material-ui/types';
import { Omit, OverridableTypeMap } from '@material-ui/types';
import { StyledComponentProps } from './styles';

export { OverridableTypeMap, Simplify, SimplifiedPropsOf } from '@material-ui/types';

/**
* A component whose root component can be controlled via a `component` prop.
*
Expand Down Expand Up @@ -56,19 +58,3 @@ export interface CommonProps extends StyledComponentProps<never> {
className?: string;
style?: React.CSSProperties;
}

export interface OverridableTypeMap {
props: {};
defaultComponent: React.ElementType;
}

/**
* @deprecated Not used in this library.
*/
export type Simplify<T> = T extends any ? { [K in keyof T]: T[K] } : never;

/**
* @deprecated Not used in this library.
*/
// tslint:disable-next-line: deprecation
export type SimplifiedPropsOf<C extends React.ElementType> = Simplify<React.ComponentProps<C>>;