首页 > 解决方案 > 无法将属性添加到 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
}

有没有办法添加这种类型的声明文件的属性?

标签: typescripttype-declaration.d.ts

解决方案


好吧,我找到了这个想法。一切都是为了增强

所以我的代码应该是

import 'passport-linkedin-oauth2'

declare module 'passport-linkedin-oauth2' {
  interface StrategyOption {
    scope?: string[]
  }
}

但我不确定以下配置的重要性有多大

tsconfig.json

"compilerOptions": {
....
    "baseUrl": ".",
    "paths": {
      "*": ["/src/types/*", "node_modules/*"]
    }
}

在我的情况下,需要扩展声明文件位于/src/types/没有任何子目录的目录中。


推荐阅读