2

I am starting to learn Typescript and so far so good when types are available to me to download. However, I have a javascript file that doesn't have its matching typescript and I would like to create my own one but I don't know how to do it or where to start.

The JS in question comes from https://docs.pci-proxy.com/inline-payment-frames.html and it is available at this url: https://pay.sandbox.datatrans.com/upp/payment/js/datatrans-inline-1.0.0.js

Could someone help me to create a basic TypeScript file that allows me to at least call the this.initTokenize function? The rest of tunctions are pretty similar so I should be able to mimic same logic by myself and learn from the example.

Thanks!

user3587624
  • 1,427
  • 5
  • 29
  • 60
  • Will this help? https://stackoverflow.com/questions/12687779/how-do-you-produce-a-d-ts-typings-definition-file-from-an-existing-javascript –  Dec 11 '17 at 02:25
  • What you are looking for is to generate a TS definition file. A search on tsd would help you write or find the definition you are looking for. – nipuna-g Dec 11 '17 at 02:30
  • You are right. I am looking for a d.ts file. – user3587624 Dec 11 '17 at 02:32
  • `tsc -d` http://www.typescriptlang.org/docs/handbook/compiler-options.html check param `-d` – Josh Lin Dec 11 '17 at 02:53
  • 1
    Possible duplicate of [How do you produce a .d.ts "typings" definition file from an existing JavaScript library?](https://stackoverflow.com/questions/12687779/how-do-you-produce-a-d-ts-typings-definition-file-from-an-existing-javascript) –  Dec 11 '17 at 13:25

1 Answers1

2

How to generate a index.d.ts file from a Javascript file

Compile the JavaScript using TypeScript with options declaration: true, allowJs: true. You will get a new .js and .d.ts file

Alternatively use the JavaScript as is with just allowJs: true in your project.

basarat
  • 261,912
  • 58
  • 460
  • 511
  • 8
    Combining the `declaration` and `allowJs` flags is not allowed. Doing so results in the message `error TS5053: Option 'allowJs' cannot be specified with option 'declaration'` – Polyov Jul 15 '18 at 00:31