简体   繁体   中英

Use Javascript Libary On Typescript Project

I want to use an payment system which is calling iyzico. The iyzico payment library is https://www.npmjs.com/package/iyzipay it. But there is not any types so how can i use this library on my node.js typescript express backend project?

i tried make one mylib.d.ts file on my root directory and put this code on this file.

declare module 'iyzipay';

After then i put this variable on my tsconfig.json file

  ,"include": [
    "src", "mylib.d.ts"
  ]

When i import the libary on my project i get an error like this.

Could not find a declaration file for module 'iyzipay'. '/Users/xxx/node_modules/iyzipay/lib/Iyzipay.js' implicitly has an 'any' type. Try npm i --save-dev @types/iyzipay if it exists or add a new declaration (.d.ts) file containing `declare module 'iyzipay';

You need to declare export types for module 'iyzipay';

For example:

declare module 'iyzipay' {

  interface IyzipayOptions {
    apiKey: string;
    secretKey: string;
    uri: string;
  }

  class Iyzipay {
    constructor (options: IyzipayOptions);
  }
  
  export default Iyzipay;
}

This type declaring is just for the simple usage from document . You should write the types as you need.

import Iyzipay from 'iyzipay';

var iyzipay = new Iyzipay({
    apiKey: 'your api key',
    secretKey: 'your secret key',
    uri: 'https://sandbox-api.iyzipay.com'
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM