father
father copied to clipboard
babel模式编译ts,无法识别声明文件
根目录下的typings.d.ts,配置如下:
执行father build --cjs babel,提示如下
尝试把typings.d.ts放到src下也是同样的问题
@sorrycc 大佬帮忙看下啊
跟踪源码发现是father-build的源码里isTsFile过滤掉了.d.ts文件,导致gulpTs获取获取声明文件。
临时解决方法:修改father-build/lib/babel.js下的isTsFile方法,去掉对.d.ts的过滤,同时把声明文件放到src目录下
临时方案:
- 在
tsconfig.json
中新增compilerOptions.typeRoots
配置:
{
"compilerOptions": {
- "types": [xxx],
+ "typeRoots": ["./typings"]
}
}
- 创建
typings/global/index.d.ts
,里面声明全局自定义的 module:
+ declare module "*.less";
- 注意
typeRoots
包含类似node_modules/@types
的默认值(参见 tsconfig 说明),进行改写默认值会失效,如果用到@types/xxx
的类型定义需要手动把默认值加回来
试试 https://github.com/umijs/father/issues/48#issuecomment-730857244
@huzhongchun 请问最后是怎么解决的呢?目前 [email protected] 仍然有这个问题
目前png仍然存在此问题
在index.ts头部显示引用 /// <reference
path="你的 xxx.d.ts 路径" />
或者xx.d.ts改成xx.ts(father-build中babel.ts过滤了d.ts)
lerna的话注意在子包的src下添加声明文件,子包中不读取根目录下的
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
.
临时方案:
- 在
tsconfig.json
中新增compilerOptions.typeRoots
配置:{ "compilerOptions": { - "types": [xxx], + "typeRoots": ["./typings"] } }
- 创建
typings/global/index.d.ts
,里面声明全局自定义的 module:+ declare module "*.less";
- 注意
typeRoots
包含类似node_modules/@types
的默认值(参见 tsconfig 说明),进行改写默认值会失效,如果用到@types/xxx
的类型定义需要手动把默认值加回来
用了这种方案还是不行
father 4 已发布,可尝试升级到最新版:https://github.com/umijs/father/blob/master/docs/guide/migrate.md
旧版本不再维护,感谢支持
用了方案还是不行,只能升级至 father 4