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

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

Closed
huzhongchun opened this issue Jun 18, 2020 · 13 comments
Closed

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

huzhongchun opened this issue Jun 18, 2020 · 13 comments
Labels

Comments

@huzhongchun
Copy link

huzhongchun commented Jun 18, 2020

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

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

@sorrycc 大佬帮忙看下啊

@huzhongchun
Copy link
Author

huzhongchun commented Jun 19, 2020

image

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

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

@daolou
Copy link

daolou commented Jul 22, 2020

我提了 pr

但没 merge,等 father3 出来吧,

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

@PeachScript
Copy link
Member

PeachScript commented Nov 3, 2020

临时方案:

  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 的类型定义需要手动把默认值加回来

@aweiu
Copy link

aweiu commented Nov 20, 2020

试试 #48 (comment)

@watsonhaw5566
Copy link

试试 #48 (comment)

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

@javaxiu
Copy link

javaxiu commented Jan 28, 2022

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

@ChenYCL
Copy link

ChenYCL commented Feb 14, 2022

目前png仍然存在此问题

@WillCoco
Copy link

WillCoco commented Mar 1, 2022

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

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

@shallinta
Copy link

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.

@ZhanYishu
Copy link

临时方案:

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

image

@PeachScript
Copy link
Member

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

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

@PeachScript PeachScript closed this as not planned Won't fix, can't repro, duplicate, stale Aug 31, 2022
@johanazhu
Copy link

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

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

No branches or pull requests