在Ionic 2中使用Trello REST - 错误TS2304找不到名字'Trello' [英] Using Trello REST in Ionic 2 - Error TS2304 Cannot find name 'Trello'

查看:954
本文介绍了在Ionic 2中使用Trello REST - 错误TS2304找不到名字'Trello'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

成为离子2和Trello REST界面的新手我需要帮助:

being a newbee to the ionic 2 and Trello REST interface I need help please:

根据Trello.com网站( https://developers.trello.com/get-started/start-building )我有:

As per the Trello.com site (https://developers.trello.com/get-started/start-building) I have:


  1. 在index.html的html行下添加,即:在他们询问的正文之前,以下内容并在我的代码中替换了AppKey:

  1. Added under the html line in the index.html ie: before the body as they ask, the following and replaced the AppKey in my code:

 < script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>

< script src="https://api.trello.com/1/client.js?key=[AppKey]"></script>


  • 根据他们的例子添加了添加卡片的代码:

  • Added code to add a card as per their example:

    var myList ='myIDLIST';

    var myList = 'myIDLIST';

    var creationSuccess = function(data) {
    
        console.log('Card created successfully. Data returned:' + JSON.stringify(data));
    };
    
    var newCard = { 
    
        name: 'New Test Card', 
        desc: 'This is the description of our new card.',
         // Place this card at the top of our list 
        idList: myList,
        pos: 'top'
    };
    
    Trello.post('/cards/', newCard, creationSuccess);
    


  • 但是我收到打字稿错误:

    However I get a typescript error:

    TypeScript error: C:/workspace/...etc..../service.ts(66,9): Error TS2304: Cannot find name 'Trello'.
    

    我认为Trello应该可以用于其他模块,因为它在index.html中声明了

    I thought Trello should be available to other modules since its declared in the index.html

    任何帮助表示赞赏。

    推荐答案

    Trello对象可能在运行时存在,但是Typescript编译器不知道它,因此它报告错误。您必须提供声明文件或只是告诉编译器它应该期望全局Trello对象。为此,将这行代码放在使用Trello对象的每个文件的开头。

    The Trello object might exist at runtime, but the Typescript compiler doesn't know about it, so it reports the errors. You have to provide the declaration files or simply tell the compiler that it should expect a global Trello object. For that put this line of code to the beginning of every file that uses the Trello object.

    declare var Trello: any;
    

    您还可以使用 node-trello 包并直接导入。

    You can also use the node-trello package and import it directly.

    这篇关于在Ionic 2中使用Trello REST - 错误TS2304找不到名字'Trello'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆