背景
我正在 TypeScript 中创建一个输出声明的 NPM 包。该项目使用来自其他包的类型声明,例如react-emotion。
问题
当我的包的声明由 TypeScript 编译时,它会为create-emotion-styled
包的类型声明生成不正确的 URL。示例:
IconStyled.ts
:
import styled from 'react-emotion';
import { BaseIcons } from './BaseIcons';
import { colors, props } from 'flooz-common';
const { INK } = colors;
interface IconsProps {
fill?: string;
stroke?: string;
strokeWidth?: string | number;
}
export const Icon = styled(BaseIcons)`
fill: ${(props: IconsProps) => (props.fill ? props.fill : 'transparent')};
stroke: ${(props: IconsProps) => (props.fill ? `transparent` : `${INK}`)};
stroke: ${(props: IconsProps) => props.stroke && props.stroke};
stroke-width: ${(props: IconsProps) =>
props.strokeWidth ? `${props.strokeWidth}px` : '4px'}};
${props.padding};
`;
IconStyled.d.ts
:
interface IconsProps {
fill?: string;
stroke?: string;
strokeWidth?: string | number;
}
export declare const Icon: import("../../../../../../../../../../Users/flim/flam/packages/flooz-icon/node_modules/create-emotion-styled/types/react").StyledStatelessComponent<IconsProps, {
className?: string;
name: string;
size: number;
}, any>;
export {};
//# sourceMappingURL=IconStyled.d.ts.map
"../../../../../../../../../../Users/flim/flam/packages/flooz-icon/node_modules/create-emotion-styled/types/react"
类型声明的路径create-emotion-styled
显然不正确。我想解决这个问题。我猜我可能有配置错误。
这是我的tsconfig.json
:
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"declaration": true,
"declarationMap": true,
"jsx": "react",
"module": "es2015",
"moduleResolution": "node",
"outDir": "../lib/esm"
"preserveConstEnums": true,
"removeComments": false,
"sourceMap": true,
"target": "es5",
"pretty": true,
"importHelpers": true,
"lib": [
"dom",
"dom.iterable",
"es5",
"es2015.collection",
"es2015.iterable"
],
"typeRoots": ["../node_modules/@types"],
"noFallthroughCasesInSwitch": true,
"noImplicitAny": true
}
}
非常感谢任何帮助/指针。