以下代码用typescript怎么写声明文件?

以下文件在TS环境中运行,怎么写声明文件?

var WechatAPI = require('wechat-api');

var api = new WechatAPI(appid, appsecret);
api.updateRemark('open_id', 'remarked', function (err, data, res) {
  // TODO
});

声明文件是这样吗?

declare class WechatAPI {
    constructor(id: string, secret: string);
    updateRemark(): void;
}

引用的时候:

import {WechatAPI} from "wechat-api";

const api = new WechatAPI(wechatAppID, wechatAppSecret);

为什么到了转换成js文件就变成这样了?

const wechat_api_1 = require("wechat-api");
const api = new wechat_api_1.WechatAPI(wechatAppID, wechatAppSecret);//这里出错了

这是整个需要写声明文件的地址,https://github.com/node-webot...

阅读 2.5k
评论
    1 个回答
    declare class WechatAPI {
        constructor(id: string, secret: string);
    
        getUser(openid: string, callback: (err: obj, result: obj) => void);
        sendText(openID: string, textSend: string, callback: (err: obj, result: obj) => void);
        updateRemark(openid: string, remark: string, callback: (err: obj, result: obj)=> void)
    }
    
    interface obj {
        [propName: string]: string;
    }
    
    export = WechatAPI;
    评论 赞赏
      撰写回答

      登录后参与交流、获取后续更新提醒