【问题标题】:Using Trello REST in Ionic 2 - Error TS2304 Cannot find name 'Trello'在 Ionic 2 中使用 Trello REST - 错误 TS2304 找不到名称“Trello”
【发布时间】:2016-11-24 12:21:51
【问题描述】:

作为 ionic 2 和 Trello REST 界面的新手,我需要帮助:

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

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

     < 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>
    
  2. 根据他们的示例添加了添加卡片的代码:

    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);
    

但是我得到一个打字稿错误:

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

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

任何帮助表示赞赏。

【问题讨论】:

    标签: rest post ionic2 trello typescript1.8


    【解决方案1】:

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

    declare var Trello: any;
    

    也可以使用node-trello包直接导入。

    【讨论】:

    • 嗨 Kuba - 高于其他人的推荐,请参阅我们在 Ionic 2 中使用 Github 的 Node-Trello - 错误 TS2304:找不到名称 'require' 中的讨论
    猜你喜欢
    • 2016-11-24
    • 1970-01-01
    • 2016-12-18
    • 2019-05-06
    • 2019-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多