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

refactor: 把 namespace 当函数调用 #229

Open
FurryR opened this issue Feb 2, 2025 · 1 comment
Open

refactor: 把 namespace 当函数调用 #229

FurryR opened this issue Feb 2, 2025 · 1 comment

Comments

@FurryR
Copy link

FurryR commented Feb 2, 2025

气不过,想了想还是提一嘴吧。

(!) Cannot call a namespace ('JSONBigInt')
src/common/sign.ts (6:22)
4: import * as JSONBigInt from "json-bigint"
5:
6: const JSONbigNative = JSONBigInt({ useNativeBigInt: true })
                         ^
7:
8: /**
(!) Cannot call a namespace ('JSONBigInt')
src/common/http/http_connection.ts (12:22)
10: import * as JSONBigInt from "json-bigint"
11:
12: const JSONbigNative = JSONBigInt({ useNativeBigInt: true })
                          ^
13: /**
14:  * @inner
(!) Cannot call a namespace ('isStream')
src/common/http/http_connection.ts (180:8)
178: async function convertReadStreamToBuffer(data: any): Promise<void> {
179:   for (const key in data) {
180:     if (isStream(data[key])) {
             ^
181:       data[key] = await getStream.buffer(data[key])
182:     }
(!) Cannot call a namespace ('isStream')
src/common/http/http_connection.ts (227:50)
225:
226: function isObject(x: any): boolean {
227:   return typeof x === "object" && !isArray(x) && !isStream(x) && !isBuffer(x) && x !== null
                                                       ^
228: }

见过 CJS require 见过 default import,还没见过全导入进来当函数调用的。请根据库自己的 example 和 export 来修改代码。
另外我注意到 http_connection.ts 的 isObject 属最差实践,应该使用 Typescript is 语法来对 x 进行约束。并将 x 的参数类型改为 unknown。库本身可能存在很多处这样的问题,恕我不能一一指出(贵司未配置 eslint),还请慢慢修复。

@FurryR
Copy link
Author

FurryR commented Feb 2, 2025

本 issue 带来的影响

部分 bundler 在处理这样的错误调用时可能会引发编译异常,或是导致编译完成的产物不可用。未来在构建新的打包方案时可能要注意相关的内容。

至于 Typescript is 则是对于用户体验(代码智能补全/类型推导)的优化,MoSCoW 原则中属于 Can have,目前这个阶段可以不用管。

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

1 participant