Skip to content

Commit

Permalink
Rename and move to types
Browse files Browse the repository at this point in the history
  • Loading branch information
merceyz committed Jun 8, 2019
1 parent ef7ac30 commit bcf0b31
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
4 changes: 1 addition & 3 deletions packages/material-ui-styles/src/makeStyles/makeStyles.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import {
Styles,
WithStylesOptions,
} from '@material-ui/styles/withStyles';

// https://stackoverflow.com/a/49928360/3406963 without generic branch types
export type IsAny<T> = 0 extends (1 & T) ? true : false;
import { IsAny } from '@material-ui/types';

export type Or<A, B, C = false> = A extends true
? true
Expand Down
10 changes: 2 additions & 8 deletions packages/material-ui-styles/src/styled/styled.d.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
import { Omit } from '@material-ui/types';
import { Omit, IsAny, CoerceEmptyInterface } from '@material-ui/types';
import {
CreateCSSProperties,
StyledComponentProps,
WithStylesOptions,
} from '@material-ui/styles/withStyles';
import * as React from 'react';

/**
* If props is any, returns empty object, otherwise T
* @internal
*/
export type GetProps<T> = 0 extends 1 & T ? {} : T;

/**
* @internal
*/
Expand All @@ -25,7 +19,7 @@ export type ComponentCreator<Component extends React.ElementType> = <Theme, Prop
JSX.LibraryManagedAttributes<Component, React.ComponentProps<Component>>,
'classes' | 'className'
> &
StyledComponentProps<'root'> & { className?: string } & GetProps<Props>
StyledComponentProps<'root'> & { className?: string } & CoerceEmptyInterface<Props>
>;

export interface StyledProps {
Expand Down
11 changes: 11 additions & 0 deletions packages/material-ui-types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,14 @@ export type Omit<T, K extends keyof any> = T extends any ? Pick<T, Exclude<keyof
* @internal
*/
export type Overwrite<T, U> = Omit<T, keyof U> & U;

/**
* Returns true if T is any, otherwise false
*/
// https://stackoverflow.com/a/49928360/3406963 without generic branch types
export type IsAny<T> = 0 extends (1 & T) ? true : false;

/**
* Returns an empty object type if T is any, otherwise returns T
*/
export type CoerceEmptyInterface<T> = IsAny<T> extends true ? {} : T;

0 comments on commit bcf0b31

Please sign in to comment.