Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
canisminor1990 opened this issue Sep 8, 2023 · 7 comments · Fixed by #711
Closed

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

canisminor1990 opened this issue Sep 8, 2023 · 7 comments · Fixed by #711

Comments

@canisminor1990
Copy link

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
Copy link
Member

.dumi 下的类型应该的确是存在错误的,之前不报错是 bug,参考:#701

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

@liangskyli
Copy link

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

@liangskyli
Copy link

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

@PeachScript
Copy link
Member

PeachScript commented Sep 12, 2023

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

两种建议的修改方式:

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

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

@PeachScript
Copy link
Member

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

@liangskyli
Copy link

@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
Copy link

后面的问题,移步到 #713

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants