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] Bump minimum required TypeScript version to 3.5 #24795

Merged
merged 7 commits into from
Feb 11, 2021
Merged
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
1 change: 0 additions & 1 deletion docs/src/pages/css-in-js/basics/AdaptingHook.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as React from 'react';
import { makeStyles } from '@material-ui/core/styles';
import Button, { ButtonProps as MuiButtonProps } from '@material-ui/core/Button';
import { Omit } from '@material-ui/types';

interface Props {
color: 'red' | 'blue';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as React from 'react';
import { styled } from '@material-ui/core/styles';
import Button, { ButtonProps } from '@material-ui/core/Button';
import { Omit } from '@material-ui/types';

interface MyButtonProps {
color: 'red' | 'blue';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ Have a look at the older [versions](https://material-ui.com/versions/) for backw

## TypeScript

Material-UI requires a minimum version of TypeScript 3.2.
Material-UI requires a minimum version of TypeScript 3.5.
1 change: 0 additions & 1 deletion docs/src/pages/guides/composition/ButtonRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import * as React from 'react';
import { MemoryRouter as Router } from 'react-router';
import { Link as RouterLink, LinkProps as RouterLinkProps } from 'react-router-dom';
import Button from '@material-ui/core/Button';
import { Omit } from '@material-ui/types';

const LinkBehavior = React.forwardRef<any, Omit<RouterLinkProps, 'to'>>(
(props, ref) => (
Expand Down
1 change: 0 additions & 1 deletion docs/src/pages/guides/composition/LinkRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import * as React from 'react';
import { MemoryRouter as Router } from 'react-router';
import { Link as RouterLink, LinkProps as RouterLinkProps } from 'react-router-dom';
import Link from '@material-ui/core/Link';
import { Omit } from '@material-ui/types';

const LinkBehavior = React.forwardRef<any, Omit<RouterLinkProps, 'to'>>(
(props, ref) => (
Expand Down
1 change: 0 additions & 1 deletion docs/src/pages/guides/composition/ListRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import DraftsIcon from '@material-ui/icons/Drafts';
import Typography from '@material-ui/core/Typography';
import { Route, MemoryRouter } from 'react-router';
import { Link as RouterLink, LinkProps as RouterLinkProps } from 'react-router-dom';
import { Omit } from '@material-ui/types';

interface ListItemLinkProps {
icon?: React.ReactElement;
Expand Down
9 changes: 9 additions & 0 deletions docs/src/pages/guides/migration-v4/migration-v4.md
Original file line number Diff line number Diff line change
Expand Up @@ -1266,3 +1266,12 @@ As the core components use emotion as a styled engine, the props used by emotion
},
});
```

### `@material-ui/types`

- Rename the exported `Omit` type in `@material-ui/types`. The module is now called `DistributiveOmit`. The change removes the confusion with the built-in `Omit` helper introduced in TypeScript v3.5. The built-in `Omit`, while similar, is non-distributive. This leads to differences when applied to union types. [See this StackOverflow answer for further details](https://stackoverflow.com/a/57103940/1009797).

```diff
-import { Omit } from '@material-ui/types';
+import { DistributiveOmit } from '@material-ui/types';
```
1 change: 0 additions & 1 deletion docs/src/pages/premium-themes/paperbase/Navigator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import SettingsInputComponentIcon from '@material-ui/icons/SettingsInputComponen
import TimerIcon from '@material-ui/icons/Timer';
import SettingsIcon from '@material-ui/icons/Settings';
import PhonelinkSetupIcon from '@material-ui/icons/PhonelinkSetup';
import { Omit } from '@material-ui/types';

const categories = [
{
Expand Down
1 change: 0 additions & 1 deletion docs/src/pages/styles/basics/AdaptingHOC.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as React from 'react';
import { withStyles, createStyles, WithStyles } from '@material-ui/core/styles';
import Button, { ButtonProps } from '@material-ui/core/Button';
import { Omit } from '@material-ui/types';

const styles = createStyles({
root: {
Expand Down
1 change: 0 additions & 1 deletion docs/src/pages/styles/basics/AdaptingHook.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as React from 'react';
import { makeStyles } from '@material-ui/core/styles';
import Button, { ButtonProps as MuiButtonProps } from '@material-ui/core/Button';
import { Omit } from '@material-ui/types';

interface Props {
color: 'red' | 'blue';
Expand Down
1 change: 0 additions & 1 deletion docs/src/pages/styles/basics/AdaptingStyledComponents.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as React from 'react';
import { styled } from '@material-ui/core/styles';
import Button, { ButtonProps } from '@material-ui/core/Button';
import { Omit } from '@material-ui/types';

interface MyButtonProps {
color: 'red' | 'blue';
Expand Down
3 changes: 2 additions & 1 deletion packages/material-ui-lab/src/DateRangePicker/RangeTypes.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { DistributiveOmit } from '@material-ui/types';
import { ParsableDate } from '../internal/pickers/constants/prop-types';
import { AllSharedPickerProps } from '../internal/pickers/Picker/SharedPickerProps';

export type RangeInput<TDate> = [ParsableDate<TDate>, ParsableDate<TDate>];
export type DateRange<TDate> = [TDate | null, TDate | null];
export type NonEmptyDateRange<TDate> = [TDate, TDate];

export type AllSharedDateRangePickerProps<TDate> = Omit<
export type AllSharedDateRangePickerProps<TDate> = DistributiveOmit<
AllSharedPickerProps<RangeInput<TDate>, DateRange<TDate>>,
'renderInput' | 'orientation'
> &
Expand Down
4 changes: 2 additions & 2 deletions packages/material-ui-lab/src/TabList/TabList.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import { TabsTypeMap } from '@material-ui/core/Tabs';
import { Omit } from '@material-ui/types';
import { DistributiveOmit } from '@material-ui/types';
import { OverridableComponent, OverrideProps } from '@material-ui/core/OverridableComponent';

export interface TabListTypeMap<
Expand All @@ -12,7 +12,7 @@ export interface TabListTypeMap<
* A list of `<Tab />` elements.
*/
children?: React.ReactElement[];
} & Omit<TabsTypeMap['props'], 'children' | 'value'>;
} & DistributiveOmit<TabsTypeMap['props'], 'children' | 'value'>;
defaultComponent: D;
}
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as React from 'react';
import { DistributiveOmit } from '@material-ui/types';
import PropTypes from 'prop-types';
import { TextFieldProps as MuiTextFieldPropsType } from '@material-ui/core/TextField';
import { IconButtonProps } from '@material-ui/core/IconButton';
Expand All @@ -9,7 +10,9 @@ import { useUtils, MuiPickersAdapter } from './hooks/useUtils';
import { getDisplayDate, getTextFieldAriaText } from './text-field-helper';

// make `variant` optional.
export type MuiTextFieldProps = MuiTextFieldPropsType | Omit<MuiTextFieldPropsType, 'variant'>;
export type MuiTextFieldProps =
| MuiTextFieldPropsType
| DistributiveOmit<MuiTextFieldPropsType, 'variant'>;

export interface DateInputProps<TInputValue = ParsableDate, TDateValue = unknown> {
open: boolean;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import * as React from 'react';
import { DistributiveOmit } from '@material-ui/types';
import { useUtils } from './useUtils';
import { ParsableDate } from '../constants/prop-types';
import { PickerOnChangeFn } from './useViews';
import { getMeridiem, convertToMeridiem } from '../time-utils';

export type OverrideParsableDateProps<TDate, TProps, TKey extends keyof TProps> = Omit<
export type OverrideParsableDateProps<TDate, TProps, TKey extends keyof TProps> = DistributiveOmit<
TProps,
TKey
> &
Expand Down
10 changes: 7 additions & 3 deletions packages/material-ui-lab/src/internal/pickers/typings/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import { WithStyles } from '@material-ui/core/styles';
import { DistributiveOmit } from '@material-ui/types';

/**
* All standard components exposed by `material-ui` are `StyledComponents` with
* certain `classes`, on which one can also set a top-level `className` and inline
* `style`.
*/
export type ExtendMui<C, Removals extends keyof C = never> = Omit<
export type ExtendMui<C, Removals extends keyof C = never> = DistributiveOmit<
C,
'classes' | 'theme' | Removals
>;

export type MakeOptional<T, K extends keyof T> = {
[P in K]?: T[P] | undefined;
} &
Omit<T, K>;
DistributiveOmit<T, K>;

export type MakeRequired<T, K extends keyof T> = {
[X in Exclude<keyof T, K>]?: T[X];
Expand All @@ -22,4 +23,7 @@ export type MakeRequired<T, K extends keyof T> = {
[P in K]-?: T[P];
};

export type WithoutClasses<TProps extends WithStyles<any>> = Omit<TProps, keyof WithStyles<any>>;
export type WithoutClasses<TProps extends WithStyles<any>> = DistributiveOmit<
TProps,
keyof WithStyles<any>
>;
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { DistributiveOmit } from '@material-ui/types';
import StaticWrapper from './StaticWrapper';
import MobileWrapper from './MobileWrapper';
import DesktopWrapper from './DesktopWrapper';
Expand All @@ -12,7 +13,7 @@ export type SomeWrapper =
| typeof DesktopWrapper
| typeof DesktopTooltipWrapper;

export type PublicWrapperProps<TWrapper extends SomeWrapper> = Omit<
export type PublicWrapperProps<TWrapper extends SomeWrapper> = DistributiveOmit<
React.ComponentProps<TWrapper>,
keyof PrivateWrapperProps
>;
Expand Down
1 change: 0 additions & 1 deletion packages/material-ui-styles/src/makeStyles/makeStyles.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ClassNameMap, Styles, WithStylesOptions } from '@material-ui/styles/withStyles';
import { Omit } from '@material-ui/types';
import { DefaultTheme } from '../defaultTheme';

export default function makeStyles<
Expand Down
4 changes: 2 additions & 2 deletions packages/material-ui-styles/src/styled/styled.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Omit, Overwrite } from '@material-ui/types';
import { DistributiveOmit, Overwrite } from '@material-ui/types';
import {
CreateCSSProperties,
StyledComponentProps,
Expand All @@ -22,7 +22,7 @@ export type ComponentCreator<Component extends React.ElementType> = <
| ((props: { theme: Theme } & Props) => CreateCSSProperties<Props>),
options?: WithStylesOptions<Theme>
) => StyledComponent<
Omit<
DistributiveOmit<
JSX.LibraryManagedAttributes<Component, React.ComponentProps<Component>>,
'classes' | 'className'
> &
Expand Down
7 changes: 5 additions & 2 deletions packages/material-ui-styles/src/withTheme/withTheme.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { ConsistentWith, Omit, PropInjector } from '@material-ui/types';
import { ConsistentWith, DistributiveOmit, PropInjector } from '@material-ui/types';
import { DefaultTheme } from '../defaultTheme';

export interface WithThemeCreatorOption<Theme = DefaultTheme> {
Expand Down Expand Up @@ -30,7 +30,10 @@ export default function withTheme<
>(
component: C
): React.ComponentType<
Omit<JSX.LibraryManagedAttributes<C, React.ComponentProps<C>>, keyof WithTheme<Theme>> &
DistributiveOmit<
JSX.LibraryManagedAttributes<C, React.ComponentProps<C>>,
keyof WithTheme<Theme>
> &
Partial<WithTheme<Theme>> &
ThemedComponentProps
>;
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,3 @@ export type SxProps<Theme extends object = {}> = SystemStyleObject<Theme>;

// eslint-disable-next-line @typescript-eslint/naming-convention
export default function unstable_styleFunctionSx(props: object): object;

// utils
export type Omit<T, K> = Pick<T, Exclude<keyof T, K>>;
7 changes: 4 additions & 3 deletions packages/material-ui-types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,17 @@ export type PropInjector<InjectedProps, AdditionalProps = {}> = <
>(
component: C
) => React.JSXElementConstructor<
Omit<JSX.LibraryManagedAttributes<C, React.ComponentProps<C>>, keyof InjectedProps> &
DistributiveOmit<JSX.LibraryManagedAttributes<C, React.ComponentProps<C>>, keyof InjectedProps> &
AdditionalProps
>;

/**
* Remove properties `K` from `T`.
* Distributive for union types.
*
* @internal
*/
export type Omit<T, K extends keyof any> = T extends any ? Pick<T, Exclude<keyof T, K>> : never;
export type DistributiveOmit<T, K extends keyof any> = T extends any ? Omit<T, K> : never;

/**
* Generate a set of string literal types with the given default record `T` and
Expand All @@ -54,7 +55,7 @@ export type OverridableStringUnion<T, U = {}> = GenerateStringUnion<Overwrite<T,
*
* @internal
*/
export type Overwrite<T, U> = Omit<T, keyof U> & U;
export type Overwrite<T, U> = DistributiveOmit<T, keyof U> & U;

type GenerateStringUnion<T> = Extract<
{
Expand Down
6 changes: 3 additions & 3 deletions packages/material-ui-unstyled/src/OverridableComponent.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { Omit } from '@material-ui/types';
import { DistributiveOmit } from '@material-ui/types';

/**
* A component whose root component can be controlled via a `component` prop.
Expand Down Expand Up @@ -28,7 +28,7 @@ export type OverrideProps<
C extends React.ElementType
> = (
& BaseProps<M>
& Omit<React.ComponentPropsWithRef<C>, keyof BaseProps<M>>
& DistributiveOmit<React.ComponentPropsWithRef<C>, keyof BaseProps<M>>
);

/**
Expand All @@ -37,7 +37,7 @@ export type OverrideProps<
// prettier-ignore
export type DefaultComponentProps<M extends OverridableTypeMap> =
& BaseProps<M>
& Omit<React.ComponentPropsWithRef<M['defaultComponent']>, keyof BaseProps<M>>;
& DistributiveOmit<React.ComponentPropsWithRef<M['defaultComponent']>, keyof BaseProps<M>>;

/**
* Props defined on the component (+ common material-ui props).
Expand Down
6 changes: 5 additions & 1 deletion packages/material-ui-utils/src/isMuiElement.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as React from 'react';
import { DistributiveOmit } from '@material-ui/types';
Copy link
Member

Choose a reason for hiding this comment

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

@material-ui/types isn't declared as a dependency of the package. It creates this fail: mui/mui-x#1046. Solved in #24936


export type ClassNameMap<ClassKey extends string = string> = Record<ClassKey, string>;

Expand All @@ -15,7 +16,10 @@ export interface StyledComponentProps<ClassKey extends string = string> {
* However, we don't declare classes on this type.
* It is recommended to declare them manually with an interface so that each class can have a separate JSDOC.
*/
export type StandardProps<C, Removals extends keyof C = never> = Omit<C, 'classes' | Removals> &
export type StandardProps<C, Removals extends keyof C = never> = DistributiveOmit<
C,
'classes' | Removals
> &
// each component declares it's classes in a separate interface for proper JSDOC
StyledComponentProps<never> & {
ref?: C extends { ref?: infer RefType } ? RefType : React.Ref<unknown>;
Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui/src/Backdrop/Backdrop.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import { SxProps } from '@material-ui/system';
import { Omit, InternalStandardProps as StandardProps, Theme } from '..';
import { InternalStandardProps as StandardProps, Theme } from '..';
import { FadeProps } from '../Fade';
import { TransitionProps } from '../transitions/transition';

Expand Down
3 changes: 2 additions & 1 deletion packages/material-ui/src/ButtonBase/ButtonBase.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as React from 'react';
import { SxProps } from '@material-ui/system';
import { DistributiveOmit } from '@material-ui/types';
import { Theme } from '../styles';
import { TouchRippleProps } from './TouchRipple';
import { OverrideProps, OverridableComponent, OverridableTypeMap } from '../OverridableComponent';
Expand Down Expand Up @@ -99,7 +100,7 @@ export interface ButtonBaseTypeMap<P = {}, D extends React.ElementType = 'button
* can make extension quite tricky
*/
export interface ExtendButtonBaseTypeMap<M extends OverridableTypeMap> {
props: M['props'] & Omit<ButtonBaseTypeMap['props'], 'classes'>;
props: M['props'] & DistributiveOmit<ButtonBaseTypeMap['props'], 'classes'>;
defaultComponent: M['defaultComponent'];
}

Expand Down
1 change: 0 additions & 1 deletion packages/material-ui/src/Fade/Fade.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as React from 'react';
import { Omit } from '..';
import { TransitionProps } from '../transitions/transition';

export interface FadeProps extends Omit<TransitionProps, 'children'> {
Expand Down
4 changes: 2 additions & 2 deletions packages/material-ui/src/GlobalStyles/GlobalStyles.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { GlobalStylesProps } from '@material-ui/styled-engine';
import { Omit } from '@material-ui/types';
import { DistributiveOmit } from '@material-ui/types';
/**
*
* API:
*
* - [Global API](https://material-ui.com/api/global/)
*/
export default function GlobalStyles(
props: Omit<GlobalStylesProps, 'defaultTheme'>
props: DistributiveOmit<GlobalStylesProps, 'defaultTheme'>
): React.ReactElement;
1 change: 0 additions & 1 deletion packages/material-ui/src/Grow/Grow.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as React from 'react';
import { Omit } from '@material-ui/types';
import { TransitionProps } from '../transitions/transition';

export interface GrowProps extends Omit<TransitionProps, 'timeout'> {
Expand Down
4 changes: 2 additions & 2 deletions packages/material-ui/src/Link/Link.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { Omit } from '@material-ui/types';
import { DistributiveOmit } from '@material-ui/types';
import { SxProps } from '@material-ui/system';
import { OverridableComponent, OverrideProps } from '../OverridableComponent';
import { Theme } from '../styles';
Expand Down Expand Up @@ -73,7 +73,7 @@ declare const Link: OverridableComponent<LinkTypeMap>;
export type LinkClassKey = keyof NonNullable<LinkTypeMap['props']['classes']>;

export type LinkBaseProps = Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, 'color'> &
Omit<TypographyProps, 'children' | 'component' | 'color' | 'variant'>;
DistributiveOmit<TypographyProps, 'children' | 'component' | 'color' | 'variant'>;

export type LinkProps<
D extends React.ElementType = LinkTypeMap['defaultComponent'],
Expand Down
4 changes: 2 additions & 2 deletions packages/material-ui/src/MenuItem/MenuItem.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Omit } from '@material-ui/types';
import { DistributiveOmit } from '@material-ui/types';
import { ListItemTypeMap, ListItemProps } from '../ListItem';
import { OverridableComponent, OverrideProps } from '../OverridableComponent';
import { ExtendButtonBase } from '../ButtonBase';
Expand All @@ -7,7 +7,7 @@ export type MenuItemClassKey = keyof NonNullable<MenuItemTypeMap['props']['class

export interface MenuItemTypeMap<P = {}, D extends React.ElementType = 'li'> {
props: P &
Omit<ListItemTypeMap<P, D>['props'], 'children'> & {
DistributiveOmit<ListItemTypeMap<P, D>['props'], 'children'> & {
/**
* The content of the component.
*/
Expand Down
Loading