打字稿环境类型声明

时间:2020-01-09 10:05:15

标签: javascript typescript type-declaration

我试图包装一个没有导出的纯js库,只是一个带有原型扩展的全局变量。 https://github.com/davidshimjs/qrcodejs

声明文件与npm库分开

  • 在研究发现正确的方法是声明一个类后,更新了类型文件
  • 仍然无法导入QRCode

declare class QRCode {

        constructor (el: HTMLElement, vOption: string|Options): IQRCode;

        public makeCode(sText: string): void

        public clear(): void
}

declare module 'davidshimjs-qrcodejs' {
    export enum CorrectLevel {
            M = 0,
            L = 1,
            H = 2,
            Q = 3
    }

    export interface Options {
            text: string,
            width: number = 256,
            height: number = 256,
            colorDark: string = '#000000',
            colorLight: string = '#ffffff',
            correctLevel: CorrectLevel
    }
}

0 个答案:

没有答案