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

关于“全局类型声明扩展”无法使用的问题 #54

Closed
Mr-Hy opened this issue Oct 29, 2024 · 2 comments
Closed

关于“全局类型声明扩展”无法使用的问题 #54

Mr-Hy opened this issue Oct 29, 2024 · 2 comments

Comments

@Mr-Hy
Copy link

Mr-Hy commented Oct 29, 2024

export {}; declare global { namespace ConfigTable { interface Iassist_contact { readonly id: number; readonly info: string; } } }
当我在全局扩展ConfigTable的命名空间,但是在tsrpc中好像是不被允许的,我始终没法在其他业务中获取到这个命名空间

@k8w
Copy link
Owner

k8w commented Oct 29, 2024

是,这是为了方便 TSRPC 协议所依赖的所有类型都可以收敛在一个文件夹内,方便同步到其它项目。
如果你确实需要全局类型,可以在 TSRPC 中定义一份,然后在全局 namespace 中建立一个别名来在代码中实现全局可用。

而 TSRPC 中的类型定义,需要每一个引用的类型都有明确的 import 位置。

例如:

interface ProtocolType {
  ...
}
  declare global {
    type GlobalType = ProtocolType
  }

@k8w k8w closed this as completed Oct 29, 2024
@Mr-Hy
Copy link
Author

Mr-Hy commented Oct 29, 2024

好的,感谢你的回答

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

2 participants