typescript - 无法将属性添加到 passport-linkedin-oauth2 声明文件的接口
问题描述
我正在尝试为“passport-linkedin-oauth2”声明文件的“StrategyOption”接口添加一个属性。它不声明任何模块或接口。只需导出接口和类
....
export interface StrategyOption {
clientID: string;
clientSecret: string;
callbackURL: string;
scopeSeparator?: string;
enableProof?: boolean;
profileFields?: string[];
}
....
export class Strategy extends passportStrategy {...}
我已经尝试过以下方法。但所有这些都失败了
/// <reference types="passport-linkedin-oauth2" />
export {}
declare global {
export interface StrategyOption {
scope?: string[] // does not work
}
}
和
export interface StrategyOption {
scope?: string[] // does not work
}
和
interface StrategyOption {
scope?: string[] // does not work
}
有没有办法添加这种类型的声明文件的属性?
解决方案
好吧,我找到了这个想法。一切都是为了增强
所以我的代码应该是
import 'passport-linkedin-oauth2'
declare module 'passport-linkedin-oauth2' {
interface StrategyOption {
scope?: string[]
}
}
但我不确定以下配置的重要性有多大
在tsconfig.json
"compilerOptions": {
....
"baseUrl": ".",
"paths": {
"*": ["/src/types/*", "node_modules/*"]
}
}
在我的情况下,需要扩展声明文件位于/src/types/
没有任何子目录的目录中。
推荐阅读
- reactjs - 如何为 Front 和 admin 页面创建多个嵌套路由
- ios - 在应用商店上会出现哪些文字
- bash - 使用awk替换bash中的文本字符串
- python - Pygame:在创建 20 个随机放置的对象时管理碰撞
- jquery - 是否有任何方法或程序可以防止 jQuery 应用除当前类之外的所有相同类?
- c# - 安装后启动应用程序时,UserPrincipal.Current.EmailAddress 不起作用
- kibana - Kibana - 如何安装本地开发的插件?
- javascript - 我可以在哪里放置timeline.js 在我的应用程序中?对于 gtmetrix
- arrays - 将数组存储到全局变量 angular
- javascript - 如何在 html 电子邮件内容中显示通过 JS 获取的月份。?