Skip to content

Commit 058e409

Browse files
petyosioliviertassinarieps1lon
authored
[types] Bump minimum required TypeScript version to 3.5 (mui#24795)
Co-authored-by: Olivier Tassinari <olivier.tassinari@gmail.com> Co-authored-by: eps1lon <silbermann.sebastian@gmail.com>
1 parent 5aba908 commit 058e409

File tree

34 files changed

+59
-62
lines changed

34 files changed

+59
-62
lines changed

docs/src/pages/css-in-js/basics/AdaptingHook.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import * as React from 'react';
22
import { makeStyles } from '@material-ui/core/styles';
33
import Button, { ButtonProps as MuiButtonProps } from '@material-ui/core/Button';
4-
import { Omit } from '@material-ui/types';
54

65
interface Props {
76
color: 'red' | 'blue';

docs/src/pages/css-in-js/basics/AdaptingStyledComponents.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import * as React from 'react';
22
import { styled } from '@material-ui/core/styles';
33
import Button, { ButtonProps } from '@material-ui/core/Button';
4-
import { Omit } from '@material-ui/types';
54

65
interface MyButtonProps {
76
color: 'red' | 'blue';

docs/src/pages/getting-started/supported-platforms/supported-platforms.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,4 @@ Have a look at the older [versions](https://material-ui.com/versions/) for backw
4747

4848
## TypeScript
4949

50-
Material-UI requires a minimum version of TypeScript 3.2.
50+
Material-UI requires a minimum version of TypeScript 3.5.

docs/src/pages/guides/composition/ButtonRouter.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import * as React from 'react';
22
import { MemoryRouter as Router } from 'react-router';
33
import { Link as RouterLink, LinkProps as RouterLinkProps } from 'react-router-dom';
44
import Button from '@material-ui/core/Button';
5-
import { Omit } from '@material-ui/types';
65

76
const LinkBehavior = React.forwardRef<any, Omit<RouterLinkProps, 'to'>>(
87
(props, ref) => (

docs/src/pages/guides/composition/LinkRouter.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import * as React from 'react';
33
import { MemoryRouter as Router } from 'react-router';
44
import { Link as RouterLink, LinkProps as RouterLinkProps } from 'react-router-dom';
55
import Link from '@material-ui/core/Link';
6-
import { Omit } from '@material-ui/types';
76

87
const LinkBehavior = React.forwardRef<any, Omit<RouterLinkProps, 'to'>>(
98
(props, ref) => (

docs/src/pages/guides/composition/ListRouter.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import DraftsIcon from '@material-ui/icons/Drafts';
1111
import Typography from '@material-ui/core/Typography';
1212
import { Route, MemoryRouter } from 'react-router';
1313
import { Link as RouterLink, LinkProps as RouterLinkProps } from 'react-router-dom';
14-
import { Omit } from '@material-ui/types';
1514

1615
interface ListItemLinkProps {
1716
icon?: React.ReactElement;

docs/src/pages/guides/migration-v4/migration-v4.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ Support for non-ref-forwarding class components in the `component` prop or as im
7272
Otherwise check out the ["Caveat with refs" section in our composition guide](/guides/composition/#caveat-with-refs) to find out how to migrate.
7373
This change affects almost all components where you're using the `component` prop or passing `children` to components that require `children` to be elements (e.g. `<MenuList><CustomMenuItem /></MenuList>`)
7474

75+
### Supported TypeScript version
76+
77+
The minimum supported version of TypeScript was increased from v3.2 to v3.5.
78+
We try to align with types released from [DefinitelyTyped](https://github.com/DefinitelyTyped/DefinitelyTyped) (i.e. packages published on npm under the `@types` namespace).
79+
We will not change the minimum supported version in a major version of Material-UI.
80+
However, we generally recommend to not use a TypeScript version older than the [lowest supported version of DefinitelyTyped](https://github.com/DefinitelyTyped/DefinitelyTyped#older-versions-of-typescript-33-and-earlier)
81+
7582
### Styled engine
7683

7784
The styled engine used in v5 by default is [`emotion`](https://github.com/emotion-js/emotion). While migration from JSS to emotion, if you are using JSS style overrides for your components (for example overrides created by `makeStyles`), you need to take care of the CSS injection order. In order to do this, you need to have on the top of your application the `StylesProvider` with the `injectFirst` option. Here is an example of it:
@@ -1266,3 +1273,12 @@ As the core components use emotion as a styled engine, the props used by emotion
12661273
},
12671274
});
12681275
```
1276+
1277+
### `@material-ui/types`
1278+
1279+
- 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).
1280+
1281+
```diff
1282+
-import { Omit } from '@material-ui/types';
1283+
+import { DistributiveOmit } from '@material-ui/types';
1284+
```

docs/src/pages/premium-themes/paperbase/Navigator.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import SettingsInputComponentIcon from '@material-ui/icons/SettingsInputComponen
2222
import TimerIcon from '@material-ui/icons/Timer';
2323
import SettingsIcon from '@material-ui/icons/Settings';
2424
import PhonelinkSetupIcon from '@material-ui/icons/PhonelinkSetup';
25-
import { Omit } from '@material-ui/types';
2625

2726
const categories = [
2827
{

docs/src/pages/styles/basics/AdaptingHOC.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import * as React from 'react';
22
import { withStyles, createStyles, WithStyles } from '@material-ui/core/styles';
33
import Button, { ButtonProps } from '@material-ui/core/Button';
4-
import { Omit } from '@material-ui/types';
54

65
const styles = createStyles({
76
root: {

docs/src/pages/styles/basics/AdaptingHook.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import * as React from 'react';
22
import { makeStyles } from '@material-ui/core/styles';
33
import Button, { ButtonProps as MuiButtonProps } from '@material-ui/core/Button';
4-
import { Omit } from '@material-ui/types';
54

65
interface Props {
76
color: 'red' | 'blue';

docs/src/pages/styles/basics/AdaptingStyledComponents.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import * as React from 'react';
22
import { styled } from '@material-ui/core/styles';
33
import Button, { ButtonProps } from '@material-ui/core/Button';
4-
import { Omit } from '@material-ui/types';
54

65
interface MyButtonProps {
76
color: 'red' | 'blue';

packages/material-ui-lab/src/TabList/TabList.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as React from 'react';
22
import { TabsTypeMap } from '@material-ui/core/Tabs';
3-
import { Omit } from '@material-ui/types';
3+
import { DistributiveOmit } from '@material-ui/types';
44
import { OverridableComponent, OverrideProps } from '@material-ui/core/OverridableComponent';
55

66
export interface TabListTypeMap<
@@ -12,7 +12,7 @@ export interface TabListTypeMap<
1212
* A list of `<Tab />` elements.
1313
*/
1414
children?: React.ReactElement[];
15-
} & Omit<TabsTypeMap['props'], 'children' | 'value'>;
15+
} & DistributiveOmit<TabsTypeMap['props'], 'children' | 'value'>;
1616
defaultComponent: D;
1717
}
1818
/**

packages/material-ui-styles/src/makeStyles/makeStyles.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { ClassNameMap, Styles, WithStylesOptions } from '@material-ui/styles/withStyles';
2-
import { Omit } from '@material-ui/types';
32
import { DefaultTheme } from '../defaultTheme';
43

54
export default function makeStyles<

packages/material-ui-styles/src/styled/styled.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Omit, Overwrite } from '@material-ui/types';
1+
import { DistributiveOmit, Overwrite } from '@material-ui/types';
22
import {
33
CreateCSSProperties,
44
StyledComponentProps,
@@ -22,7 +22,7 @@ export type ComponentCreator<Component extends React.ElementType> = <
2222
| ((props: { theme: Theme } & Props) => CreateCSSProperties<Props>),
2323
options?: WithStylesOptions<Theme>
2424
) => StyledComponent<
25-
Omit<
25+
DistributiveOmit<
2626
JSX.LibraryManagedAttributes<Component, React.ComponentProps<Component>>,
2727
'classes' | 'className'
2828
> &

packages/material-ui-styles/src/withTheme/withTheme.d.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react';
2-
import { ConsistentWith, Omit, PropInjector } from '@material-ui/types';
2+
import { ConsistentWith, DistributiveOmit, PropInjector } from '@material-ui/types';
33
import { DefaultTheme } from '../defaultTheme';
44

55
export interface WithThemeCreatorOption<Theme = DefaultTheme> {
@@ -30,7 +30,10 @@ export default function withTheme<
3030
>(
3131
component: C
3232
): React.ComponentType<
33-
Omit<JSX.LibraryManagedAttributes<C, React.ComponentProps<C>>, keyof WithTheme<Theme>> &
33+
DistributiveOmit<
34+
JSX.LibraryManagedAttributes<C, React.ComponentProps<C>>,
35+
keyof WithTheme<Theme>
36+
> &
3437
Partial<WithTheme<Theme>> &
3538
ThemedComponentProps
3639
>;

packages/material-ui-system/src/styleFunctionSx/styleFunctionSx.d.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,3 @@ export type SxProps<Theme extends object = {}> = SystemStyleObject<Theme>;
5555

5656
// eslint-disable-next-line @typescript-eslint/naming-convention
5757
export default function unstable_styleFunctionSx(props: object): object;
58-
59-
// utils
60-
export type Omit<T, K> = Pick<T, Exclude<keyof T, K>>;

packages/material-ui-types/index.d.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,17 @@ export type PropInjector<InjectedProps, AdditionalProps = {}> = <
2727
>(
2828
component: C
2929
) => React.JSXElementConstructor<
30-
Omit<JSX.LibraryManagedAttributes<C, React.ComponentProps<C>>, keyof InjectedProps> &
30+
DistributiveOmit<JSX.LibraryManagedAttributes<C, React.ComponentProps<C>>, keyof InjectedProps> &
3131
AdditionalProps
3232
>;
3333

3434
/**
3535
* Remove properties `K` from `T`.
36+
* Distributive for union types.
3637
*
3738
* @internal
3839
*/
39-
export type Omit<T, K extends keyof any> = T extends any ? Pick<T, Exclude<keyof T, K>> : never;
40+
export type DistributiveOmit<T, K extends keyof any> = T extends any ? Omit<T, K> : never;
4041

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

5960
type GenerateStringUnion<T> = Extract<
6061
{

packages/material-ui-unstyled/src/OverridableComponent.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react';
2-
import { Omit } from '@material-ui/types';
2+
import { DistributiveOmit } from '@material-ui/types';
33

44
/**
55
* A component whose root component can be controlled via a `component` prop.
@@ -28,7 +28,7 @@ export type OverrideProps<
2828
C extends React.ElementType
2929
> = (
3030
& BaseProps<M>
31-
& Omit<React.ComponentPropsWithRef<C>, keyof BaseProps<M>>
31+
& DistributiveOmit<React.ComponentPropsWithRef<C>, keyof BaseProps<M>>
3232
);
3333

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

4242
/**
4343
* Props defined on the component (+ common material-ui props).

packages/material-ui-utils/src/isMuiElement.d.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as React from 'react';
2+
import { DistributiveOmit } from '@material-ui/types';
23

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

@@ -15,7 +16,10 @@ export interface StyledComponentProps<ClassKey extends string = string> {
1516
* However, we don't declare classes on this type.
1617
* It is recommended to declare them manually with an interface so that each class can have a separate JSDOC.
1718
*/
18-
export type StandardProps<C, Removals extends keyof C = never> = Omit<C, 'classes' | Removals> &
19+
export type StandardProps<C, Removals extends keyof C = never> = DistributiveOmit<
20+
C,
21+
'classes' | Removals
22+
> &
1923
// each component declares it's classes in a separate interface for proper JSDOC
2024
StyledComponentProps<never> & {
2125
ref?: C extends { ref?: infer RefType } ? RefType : React.Ref<unknown>;

packages/material-ui/src/Backdrop/Backdrop.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as React from 'react';
22
import { SxProps } from '@material-ui/system';
3-
import { Omit, InternalStandardProps as StandardProps, Theme } from '..';
3+
import { InternalStandardProps as StandardProps, Theme } from '..';
44
import { FadeProps } from '../Fade';
55
import { TransitionProps } from '../transitions/transition';
66

packages/material-ui/src/Fade/Fade.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import * as React from 'react';
2-
import { Omit } from '..';
32
import { TransitionProps } from '../transitions/transition';
43

54
export interface FadeProps extends Omit<TransitionProps, 'children'> {
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { GlobalStylesProps } from '@material-ui/styled-engine';
2-
import { Omit } from '@material-ui/types';
2+
import { DistributiveOmit } from '@material-ui/types';
33
/**
44
*
55
* API:
66
*
77
* - [Global API](https://material-ui.com/api/global/)
88
*/
99
export default function GlobalStyles(
10-
props: Omit<GlobalStylesProps, 'defaultTheme'>
10+
props: DistributiveOmit<GlobalStylesProps, 'defaultTheme'>
1111
): React.ReactElement;

packages/material-ui/src/Grow/Grow.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import * as React from 'react';
2-
import { Omit } from '@material-ui/types';
32
import { TransitionProps } from '../transitions/transition';
43

54
export interface GrowProps extends Omit<TransitionProps, 'timeout'> {

packages/material-ui/src/Link/Link.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react';
2-
import { Omit } from '@material-ui/types';
2+
import { DistributiveOmit } from '@material-ui/types';
33
import { SxProps } from '@material-ui/system';
44
import { OverridableComponent, OverrideProps } from '../OverridableComponent';
55
import { Theme } from '../styles';
@@ -73,7 +73,7 @@ declare const Link: OverridableComponent<LinkTypeMap>;
7373
export type LinkClassKey = keyof NonNullable<LinkTypeMap['props']['classes']>;
7474

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

7878
export type LinkProps<
7979
D extends React.ElementType = LinkTypeMap['defaultComponent'],

packages/material-ui/src/MenuItem/MenuItem.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Omit } from '@material-ui/types';
1+
import { DistributiveOmit } from '@material-ui/types';
22
import { ListItemTypeMap, ListItemProps } from '../ListItem';
33
import { OverridableComponent, OverrideProps } from '../OverridableComponent';
44
import { ExtendButtonBase } from '../ButtonBase';
@@ -7,7 +7,7 @@ export type MenuItemClassKey = keyof NonNullable<MenuItemTypeMap['props']['class
77

88
export interface MenuItemTypeMap<P = {}, D extends React.ElementType = 'li'> {
99
props: P &
10-
Omit<ListItemTypeMap<P, D>['props'], 'children'> & {
10+
DistributiveOmit<ListItemTypeMap<P, D>['props'], 'children'> & {
1111
/**
1212
* The content of the component.
1313
*/

packages/material-ui/src/OverridableComponent.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react';
2-
import { Omit } from '@material-ui/types';
2+
import { DistributiveOmit } from '@material-ui/types';
33
import { StyledComponentProps } from './styles';
44

55
/**
@@ -29,7 +29,7 @@ export type OverrideProps<
2929
C extends React.ElementType
3030
> = (
3131
& BaseProps<M>
32-
& Omit<React.ComponentPropsWithRef<C>, keyof BaseProps<M>>
32+
& DistributiveOmit<React.ComponentPropsWithRef<C>, keyof BaseProps<M>>
3333
);
3434

3535
/**
@@ -38,7 +38,7 @@ export type OverrideProps<
3838
// prettier-ignore
3939
export type DefaultComponentProps<M extends OverridableTypeMap> =
4040
& BaseProps<M>
41-
& Omit<React.ComponentPropsWithRef<M['defaultComponent']>, keyof BaseProps<M>>;
41+
& DistributiveOmit<React.ComponentPropsWithRef<M['defaultComponent']>, keyof BaseProps<M>>;
4242

4343
/**
4444
* Props defined on the component (+ common material-ui props).

packages/material-ui/src/Popper/Popper.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as React from 'react';
22
import { Instance, VirtualElement, Options, OptionsGeneric } from '@popperjs/core';
3-
import { Omit } from '..';
43
import { PortalProps } from '../Portal';
54

65
export type PopperPlacementType = Options['placement'];

packages/material-ui/src/SwipeableDrawer/SwipeableDrawer.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import * as React from 'react';
2-
import { Omit } from '@material-ui/types';
32
import { DrawerProps } from '../Drawer';
43

54
export interface SwipeableDrawerProps extends Omit<DrawerProps, 'onClose' | 'open'> {

packages/material-ui/src/TablePagination/TablePagination.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import * as React from 'react';
2-
import { Omit } from '@material-ui/types';
32
import { OverridableComponent, OverrideProps } from '../OverridableComponent';
43
import { TablePaginationActionsProps } from './TablePaginationActions';
54
import { TableCellProps } from '../TableCell';

packages/material-ui/src/TextareaAutosize/TextareaAutosize.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import * as React from 'react';
2-
import { Omit } from '..';
32

43
export interface TextareaAutosizeProps
54
extends Omit<React.TextareaHTMLAttributes<HTMLTextAreaElement>, 'children' | 'rows'> {

packages/material-ui/src/index.d.ts

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,20 @@
11
import * as React from 'react';
2-
import { Omit } from '@material-ui/types';
2+
import { DistributiveOmit } from '@material-ui/types';
33
import { StyledComponentProps } from './styles';
44

55
export { StyledComponentProps };
66

7-
/**
8-
* @deprecated
9-
* Import from `@material-ui/types` instead
10-
*
11-
* TODO: to remove in v5
12-
*/
13-
export { Omit };
14-
157
/**
168
* All standard components exposed by `material-ui` are `StyledComponents` with
179
* certain `classes`, on which one can also set a top-level `className` and inline
1810
* `style`.
1911
* @deprecated will be removed in v5 for internal usage only
2012
*/
21-
export type StandardProps<C, ClassKey extends string, Removals extends keyof C = never> = Omit<
13+
export type StandardProps<
2214
C,
23-
'classes' | Removals
24-
> &
15+
ClassKey extends string,
16+
Removals extends keyof C = never
17+
> = DistributiveOmit<C, 'classes' | Removals> &
2518
StyledComponentProps<ClassKey> & {
2619
className?: string;
2720
ref?: C extends { ref?: infer RefType } ? RefType : React.Ref<unknown>;
@@ -35,7 +28,7 @@ export type StandardProps<C, ClassKey extends string, Removals extends keyof C =
3528
* However, we don't declare classes on this type.
3629
* It is recommended to declare them manually with an interface so that each class can have a separate JSDOC.
3730
*/
38-
export type InternalStandardProps<C, Removals extends keyof C = never> = Omit<
31+
export type InternalStandardProps<C, Removals extends keyof C = never> = DistributiveOmit<
3932
C,
4033
'classes' | Removals
4134
> &

0 commit comments

Comments
 (0)