繁体   English   中英

类型 Generics:覆盖 MaterialUI 主题类型

[英]Type Generics: Overriding MaterialUI Theme Type

我正在尝试从 Material UI 向Theme界面添加属性,并且我已经从这篇文章中实现了解决方案:

import { createMuiTheme, Theme } from '@material-ui/core/styles';
import { Typography } from '@material-ui/core/styles/createTypography';

type Modify<T, R> = Omit<T, keyof R> & R;

export type CustomTypography = Modify<
  Typography,
  {
    secondaryFontFamily: string;
  }
>;

export type CustomTheme = Modify<
  Theme,
  {
    typography: CustomTypography;
  }
>;

export const createCustomTheme = (): CustomTheme => {
  const baseTheme = createMuiTheme();

  return {
    ...baseTheme,
    typography: {
      secondaryFontFamily: 'Georgia',
    },
  };
};

但是, Modify类型 function 的嵌套使用似乎存在一些问题,产生以下错误:

Type '{ secondaryFontFamily: string; }' is not assignable to type 'Modify<Typography, { secondaryFontFamily: string; }>'.

这是一个堆栈闪电战

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM