typescript - 如何覆盖 Typescript 中的参数
问题描述
我想为我的班级提供多个接口。
例子:
type OAuthCliStrategyOpts = {
oauthStrategy: express.Handler;
oauthStrategyOptions: object;
appKey: string;
appSecret: string;
};
type OAuthCliDefaultOpts = {
authorizationURL: string;
tokenURL: string;
appKey: string;
appSecret: string;
callbackURL?: string;
};
type OAuthCliOpts = OAuthCliDefaultOpts | OAuthCliStrategyOpts;
但是当我尝试指定时:
oauthCLI({
oauthStrategy: DropboxOAuth2Strategy,
oauthStrategyOptions: {
apiVersion: "2"
},
appSecret: "KEY",
appKey: "SECRET"
})
我收到一个错误:
Argument of type '{ oauthStrategy: any; oauthStrategyOptions: { apiVersion: string; }; appSecret: string; appKey: string; }' is not assignable to parameter of type 'OAuthCliOpts'.
Object literal may only specify known properties, and 'oauthStrategy' does not exist in type 'OAuthCliOpts'.
146 oauthStrategy: DropboxOAuth2Strategy,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```
解决方案
尝试这个
oauthCLI({ oauthStrategy: DropboxOAuth2Strategy, oauthStrategyOptions: { apiVersion: "2" }, appSecret: "KEY", appKey: "SECRET" } as OAuthCliStrategyOpts)
推荐阅读
- python - 将字符串转换为带有模式的几个变量
- c# - 列加载事件以设置子级边距
- ffmpeg - ffmpeg 到 Youtube Live 停止工作。ffmpeg 继续运行
- html - 将禁用属性传递给子组件中的 HTML 元素不起作用
- intellij-idea - 带有@GrailsCompileStatic 注解的Grails GORM 类在静态映射闭包表、版本、autoTimestamp 中显示为未解析符号
- java - 选定的值保留保存在带有单选按钮 Android 的 Dialogfragment 中
- java - 使用 AsyncTask 在 Android 中按时间间隔运行 HTTPS 请求
- python-3.x - 每次运行时,我的 python 脚本中的一段代码都会出错
- python - Python中的多值行数
- javascript - 在JS中剪切字符串的开头和结尾