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

[styles] Overload function signature instead of conditional #19320

Merged
merged 3 commits into from
Jan 21, 2020

Conversation

eps1lon
Copy link
Member

@eps1lon eps1lon commented Jan 20, 2020

@material-ui/types BREAKING CHANGE:
Or, And, IsAny and IsEmptyInterface have been removed. They are not used internally anymore and only add maintenance burden at this point. This is the latest version of those types:

/**	
 * 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;	

export type Or<A, B, C = false> = A extends true	
  ? true	
  : B extends true	
  ? true	
  : C extends true	
  ? true	
  : false;	

export type And<A, B, C = true> = A extends true	
  ? B extends true	
    ? C extends true	
      ? true	
      : false	
    : false	
  : false;	

/**	
 * @internal	
 *	
 * check if a type is `{}`	
 *	
 * 1. false if the given type has any members	
 * 2. false if the type is `object` which is the only other type with no members	
 *  {} is a top type so e.g. `string extends {}` but not `string extends object`	
 * 3. false if the given type is `unknown`	
 */	
export type IsEmptyInterface<T> = And<	
  keyof T extends never ? true : false,	
  string extends T ? true : false,	
  unknown extends T ? false : true	
>;

Simplifies the signature of makeStyles regarding useStyles() vs useStyles(props: SomePropsType). Function overload can be used instead of conditional types. Since they might be the reason for slow types (see #19113) we got rid of them.

@mui-pr-bot
Copy link

No bundle size changes comparing d30e6bb...7e72feb

Generated by 🚫 dangerJS against 7e72feb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants