father icon indicating copy to clipboard operation
father copied to clipboard

babel模式编译ts,无法识别声明文件

Open huzhongchun opened this issue 4 years ago • 11 comments

根目录下的typings.d.ts,配置如下: image 执行father build --cjs babel,提示如下

image 尝试把typings.d.ts放到src下也是同样的问题

@sorrycc 大佬帮忙看下啊

huzhongchun avatar Jun 18 '20 12:06 huzhongchun

image

跟踪源码发现是father-build的源码里isTsFile过滤掉了.d.ts文件,导致gulpTs获取获取声明文件。

临时解决方法:修改father-build/lib/babel.js下的isTsFile方法,去掉对.d.ts的过滤,同时把声明文件放到src目录下

huzhongchun avatar Jun 19 '20 05:06 huzhongchun

我提了 pr

但没 merge,等 father3 出来吧,

或者你可以看看我这里是怎么处理的

daolou avatar Jul 22 '20 09:07 daolou

临时方案:

  1. tsconfig.json 中新增 compilerOptions.typeRoots 配置:
{
  "compilerOptions": {
-    "types": [xxx],
+    "typeRoots": ["./typings"]
  }
}
  1. 创建 typings/global/index.d.ts,里面声明全局自定义的 module:
+ declare module "*.less";
  1. 注意 typeRoots 包含类似 node_modules/@types 的默认值(参见 tsconfig 说明),进行改写默认值会失效,如果用到 @types/xxx 的类型定义需要手动把默认值加回来

PeachScript avatar Nov 03 '20 06:11 PeachScript

试试 https://github.com/umijs/father/issues/48#issuecomment-730857244

aweiu avatar Nov 20 '20 05:11 aweiu

试试 #48 (comment)

这个有用,但是感觉是build的时候gulp找不到typing文件了。期待dumi3可以修复这个问题。

watsonhaw5566 avatar Dec 28 '21 09:12 watsonhaw5566

@huzhongchun 请问最后是怎么解决的呢?目前 [email protected] 仍然有这个问题

javaxiu avatar Jan 28 '22 03:01 javaxiu

目前png仍然存在此问题

ChenYCL avatar Feb 14 '22 09:02 ChenYCL

在index.ts头部显示引用 /// <reference path="你的 xxx.d.ts 路径" /> 或者xx.d.ts改成xx.ts(father-build中babel.ts过滤了d.ts)

lerna的话注意在子包的src下添加声明文件,子包中不读取根目录下的

WillCoco avatar Mar 01 '22 15:03 WillCoco

I run into the same issue. Temporary solution was to add a triple slash reference sentence. But would cause an eslint error in type of @typescript-eslint/triple-slash-reference.

shallinta avatar Mar 09 '22 07:03 shallinta

临时方案:

  1. tsconfig.json 中新增 compilerOptions.typeRoots 配置:
{
  "compilerOptions": {
-    "types": [xxx],
+    "typeRoots": ["./typings"]
  }
}
  1. 创建 typings/global/index.d.ts,里面声明全局自定义的 module:
+ declare module "*.less";
  1. 注意 typeRoots 包含类似 node_modules/@types 的默认值(参见 tsconfig 说明),进行改写默认值会失效,如果用到 @types/xxx 的类型定义需要手动把默认值加回来

用了这种方案还是不行

ZhanYishu avatar Jun 16 '22 08:06 ZhanYishu

image

ZhanYishu avatar Jun 16 '22 08:06 ZhanYishu

father 4 已发布,可尝试升级到最新版:https://github.com/umijs/father/blob/master/docs/guide/migrate.md

旧版本不再维护,感谢支持

PeachScript avatar Aug 31 '22 11:08 PeachScript

用了方案还是不行,只能升级至 father 4

johanazhu avatar Jan 31 '23 05:01 johanazhu