从节点模块导出时,类型声明使用错误的路径

时间:2018-07-17 00:36:38

标签: typescript npm emotion

背景

我正在用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
    }
}

任何帮助/指针都非常感谢。

0 个答案:

没有答案