ค้นหาเว็บไซต์

typescript - ไม่สามารถเพิ่มคุณสมบัติให้กับอินเทอร์เฟซสำหรับไฟล์การประกาศ passport-linkedin-oauth2


ฉันกำลังพยายามเพิ่มคุณสมบัติให้กับอินเทอร์เฟซ 'StrategyOption' สำหรับไฟล์ประกาศ 'passport-linkedin-oauth2' ซึ่งมันไม่ได้ประกาศโมดูลหรืออินเทอร์เฟซใดๆ เพียงแค่ส่งออกอินเทอร์เฟซและคลาส

....
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
}

มีวิธีใดในการเพิ่มคุณสมบัติในไฟล์ประกาศประเภทนี้หรือไม่?

คำตอบ #1

เอาล่ะ ฉันพบแนวคิดแล้ว มันเกี่ยวกับการเพิ่มประสิทธิภาพ

ดังนั้นโค้ดของฉันควรจะเป็น

import 'passport-linkedin-oauth2'

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

แต่ฉันไม่แน่ใจเกี่ยวกับความสำคัญของการตั้งค่าต่อไปนี้มากแค่ไหน

ใน tsconfig.json

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

ต้องการไฟล์ประกาศส่วนขยายให้อยู่ในไดเรกทอรี /src/types/ ในกรณีของฉันโดยไม่มีไดเรกทอรีย่อยใด ๆ