Using Trello REST in Ionic 2 - Error TS2304 Cannot

2019-09-13 05:43发布

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

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

  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>
    
  2. Added code to add a card as per their example:

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

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

Any help appreciated.

1条回答
小情绪 Triste *
2楼-- · 2019-09-13 06:31

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;

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

查看更多
登录 后发表回答