reactjs - 打字稿模块扩充是否会自动导出到组件库中?
问题描述
material-ui
我在后台使用和 Typescript创建了一个组件库。我使用 Typescript 模块扩充来为主题添加新选项,如他们使用 Typescript文档进行主题定制中所述。
// createPalette.d.ts/* eslint-disable @typescript-eslint/no-unused-vars */
import { Palette, PaletteOptions } from "@material-ui/core/styles/createPalette";
declare module "@material-ui/core/styles/createPalette" {
interface Palette {
highlight: PaletteColor;
layout: LayoutPaletteColor;
}
interface PaletteOptions {
highlight: PaletteColorOptions;
layout?: LayoutPaletteColor;
}
interface LayoutPaletteColorOptions {
paper: string;
text: string;
}
interface SidebarPaletteColorOptions extends LayoutPaletteColorOptions {
navItemSelectedBg: string;
navItemSelectedColor: string;
}
interface LayoutPaletteColor {
header: LayoutPaletteColorOptions;
sidebar: SidebarPaletteColorOptions;
footer: LayoutPaletteColorOptions;
}
}
然后,我构建我的项目并将其发布到 Github 包。我也在使用这个脚本,它将文件复制到*.d.ts
文件dist
夹
"copy-typings": "copyfiles -u 1 \"./src/types/*.d.ts\" dist",
例如,当我在另一个项目中安装包并引用 Header 时,我收到此错误
Cannot read property 'header' of undefined
指向theme.palette.layout.header.paper
引用的行。
这让我相信 mycreatePalette.d.ts
只对组件库本身有效,而不是当组件在另一个项目中使用时。
如何导出这个模块扩充?或者如何使这项工作?
解决方案
推荐阅读
- java - 如何使用 Eclipse 文本编辑器将字符串显示/编辑/保存到 RCP 应用程序中?
- python - 在 python 3 中列出从 3 到 21 的素数
- python - 无法使用 Yahoo Fantasy Sports API 找到统计数据
- c - 如何在c中打开具有用户定义名称的文件
- shell - 我可以在同一行打印数组索引和值吗?
- visual-studio-code - Visual Studio Code 不会注释掉空行
- cmake - 将 target_link_libraries 用于不以 lib* 开头的库
- ios - 如何在 ios 中制作类似 ig 故事加载样式的动画?
- http - 使用标头过滤代理的响应标头
- ios - ld: 找不到框架 FBAudienceNetwork