导入自定义 npm 包时智能感知不起作用

问题描述 投票:0回答:1

我有一个使用故事书创建的自定义 npm 包。导入组件时,这些组件在其他项目中工作正常,但智能感知不起作用。当我在故事书中导入相同的组件时,智能感知工作正常。

例如,以故事书中的以下组件为例:

import React from "react";
import { Card as AntCard, CardProps as AntCardProps } from "antd";

interface CardProps extends AntCardProps {
  title: string;
  extra: string;
}

const Card: React.FC<CardProps> = (props) => {
  return <AntCard {...props} />;
};

export default Card;
export type { CardProps };

我将其导出如下:

从“./Components/Card”导出{默认为卡};

构建和发布后,我正在导入其他项目,如下所示:

import Card from 'my-ui-kit';

该组件再次工作正常,但当其他开发人员无法访问该组件所具有的属性时,他们会感到困难。

打字稿版本5.3.3 反应版本 18.2

reactjs typescript npm storybook
1个回答
0
投票

这表明以下一项或多项可能是正确的:

  • 您可能忘记将
    "declaration": true
    添加到 tsconfig.json 中,以便在构建包时,它会创建
    .d.ts
    文件。这些也将被发布。
  • 您可能忘记在 package.json 中添加
    "types": "<path to .d.ts entry file>"
    行,以便使用包知道类型声明在哪里。
© www.soinside.com 2019 - 2024. All rights reserved.