GUMA GUMA - 1 year ago 60
TypeScript Question

using TypeScript for 1 single file in a big project

I've forked a very big project from GitHub and I've wrote a ~3000 lines plugin (single file) for it.
I would like to start using TypeScript for just this 1 single file.

As a starting point I only want to have the plain old JS content inside the .ts file (since any JS is valid TS) and then starting making minor incremental changes towards TS.
What I did was to install TypeScript in the project directory and made it so that TSC will compile my TypeScript file containing the old JS code into a .js file having the name the plugin had before.

The problem is this: How can I convert the plugin dependencies to TS?


the pre TS file, myPlugin.js, is the ~3000 lines file:

bigForkedApp.MyPlugin = function(bigForkedAppContext) {
// alot of code goes here

When copying this code in myPlugin.ts and expecting it to translate nicely into myPlugin.js, the compiler complains it doesn't know who bigForkedApp is.

I'm expecting that after the transpilation, the bigForkedApp.MyPlugin function in myPlugin.js can be called by the application just like before.

Should I write somehow .d.ts definitions for bigForkedApp and bigForkedAppContext?


Answer Source

since it's a JS (not TS) - you need to tell TypeScript who is "bigForkedApp", like this:

`declare var bigForkedApp: any;`