umijs / father

NPM package development tool
MIT License
2.11k stars 272 forks source link

[Bug] Generate declaration files fail in `4.3.2` and `4.3.3` #710

Closed canisminor1990 closed 12 months ago

canisminor1990 commented 12 months ago

Father build Generate declaration files 在 4.3.24.3.3 报错,4.3.1 中正常

event - Generate declaration files...
error - .dumi/tmp/core/history.ts:9:17 - TS2742: The inferred type of 'createHistory' cannot be named without a reference to '.pnpm/history@5.3.0/node_modules/history'. This is likely not portable. A type annotation is necessary.
error - src/ChatList/Item.tsx:97:27 - TS2786: 'RenderItem' cannot be used as a JSX component.
  Its return type 'ReactNode' is not a valid JSX element.
    Type 'undefined' is not assignable to type 'Element | null'.
error - src/EditableMessageList/index.tsx:32:3 - TS2345: Argument of type '({ disabled, dataSources, onChange }: EditableMessageListProps) => Element | undefined' is not assignable to parameter of type 'FunctionComponent<EditableMessageListProps>'.
  Type 'Element | undefined' is not assignable to type 'ReactElement<any, any> | null'.
error - src/Features/index.tsx:29:3 - TS2345: Argument of type '({ items, className, itemClassName, itemStyle, maxWidth, style, ...props }: FeaturesProps) => Element | undefined' is not assignable to parameter of type 'FunctionComponent<FeaturesProps>'.
  Type 'Element | undefined' is not assignable to type 'ReactElement<any, any> | null'.
error - src/FontLoader/index.tsx:17:42 - TS2345: Argument of type '({ url }: FontLoaderProps) => boolean' is not assignable to parameter of type 'FunctionComponent<FontLoaderProps>'.
...

https://github.com/lobehub/lobe-ui/actions/runs/6108436253/job/16583229714

PeachScript commented 12 months ago

.dumi 下的类型应该的确是存在错误的,之前不报错是 bug,参考:https://github.com/umijs/father/pull/701

.dumi 下的类型错误我复现看下

liangskyli commented 12 months ago

"typescript": "^5.2.2", Father build Generate declaration files 也有问题

image
liangskyli commented 12 months ago

father@4.3.1正常,father@4.3.3有问题

PeachScript commented 12 months ago

tsconfig.jsoninclude 配置项中的 .dumi/**/* 可以去掉,dumi 提供的模板有问题,框架临时文件不应该被 include

两种建议的修改方式:

  1. 如果 .dumi 下有本地主题、运行时插件等非临时文件,那么在 exclude 中新增 .dumi/{tmp,tmp-*} 或者把 include 改成 .dumi/theme
  2. 如果 .dumi 下只有临时文件,那么去掉 .dumi/**/* 即可

dumi 下个版本会更新 warning 和脚手架,并增加 tsconfig 自动修正逻辑

PeachScript commented 12 months ago

v4.3.4 修复了该问题,方案是过滤掉不属于 father 编译源文件产生的类型错误,可以更新到新版试试看

liangskyli commented 11 months ago

@PeachScript :v4.3.4下, 编译错误

error - src/foo2/index.tsx:8:7 - TS2742: The inferred type of 'Foo2' cannot be named without a reference to 'packages/demo2/node_modules/@types/react/ts5.0/jsx-runtime'. This is likely not portable. A type annotation is necessary.
error - src/foo2/index.tsx:8:7 - TS2742: The inferred type of 'Foo2' cannot be named without a reference to 'packages/demo2/node_modules/@types/react/ts5.0/jsx-runtime'. This is likely not portable. A type annotation is necessary.
error - Error: Declaration generation failed.

编译错误代码

type IFoo2Props = {
  /**
   * @description 标题
   * @default "默认值"
   */
  title: string;
};
const Foo2 = (props: IFoo2Props) => <h4>{props.title}</h4>;

export default Foo2;

这样就编译正常

import type { FC } from 'react';

type IFoo2Props = {
  /**
   * @description 标题
   * @default "默认值"
   */
  title: string;
};
const Foo2: FC<IFoo2Props> = (props) => <h4>{props.title}</h4>;

export default Foo2;
liangskyli commented 11 months ago

后面的问题,移步到 #713