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

关于TS类型的一些问题 #71

Open
otakustay opened this issue Jul 21, 2020 · 6 comments
Open

关于TS类型的一些问题 #71

otakustay opened this issue Jul 21, 2020 · 6 comments

Comments

@otakustay
Copy link
Collaborator

第一个问题是package.json中没有types字段,所以解析不到:

image

第二个问题是代码库用了export =导出整个,但实际上我觉得应该是named export更合适些?

@otakustay
Copy link
Collaborator Author

另外BosEndpoint这个类型感觉没必要,就用string类型就好了

原因是endpoint很多时候是用配置拼出来的,比如这样:

endpoint: `https://${process.env.BCE_REGION}.bcebos.com`

TS是无法推导这个类型到BosEndpoint上面去的,不得不用as BosEndpoint去搞定,没啥意思

@fwh1990
Copy link

fwh1990 commented Apr 9, 2021

只能 +1 了

@shenlanchenwei
Copy link

+1

@sknightq
Copy link

为啥types在packagejson里这么重要的不处理下?害我研究了半天

@peterwang-s
Copy link

peterwang-s commented Jun 8, 2022

  1. 联系百度官网人员,说明是暂时不支持TS
  2. 我的解决方法是

全局 .d.ts

declare module '@baiducloud/sdk'
declare module '@baiducloud/sdk/dist/baidubce-sdk.bundle'

引用 .ts 文件中

import type SDK from '@baiducloud/sdk/types' 

直接找到类型文件进行使用

PS:另外官方的类型声明文件不太好使,最后我放弃使用了。估计是SDK升级,并没有同步更新 d.ts

@tjx666
Copy link

tjx666 commented Jul 20, 2024

临时解决办法:

//  module.d.ts

declare module '@baiducloud/sdk' {
  import sdk from '@baiducloud/sdk/types';
  export default sdk;
}

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

No branches or pull requests

6 participants