I m actually trying to work with both coffeescript and typescript in the same project.
In fact, I want to be able to chose which one I prefer when coding.
The fact is that the javascript generated by typescript doesn't seem to work as expected with the javascript generated with coffeescript
Explanation :
I wrote a Controller class with coffeescript which works perfectly when I extend it in a coffeescript file like below :
Controller = require('../node_modules/Controller/Controller')
class HelloController extends Controller
indexAction: (name) =>
console.log 'hey '+ name
module.exports = HelloController
But when I try to use it with typescript like below :
import Controller = require('../node_modules/Controller/Controller');
export class HelloController extends Controller {
constructor() {
super()
}
indexAction(name:String) {
console.log('hey '+name);
}
}
I got an error telling me that the controller cant be find at the expected place (the .js file is well generated)
Can you help me ?
If you want to do this, you'll need to supply type information about the Coffeescript-generated JavaScript file.
If you add a Controller.d.ts
you can describe the types in your controller file so TypeScript can apply that type information during compilation.
For example:
declare class Controller {
protected name: string;
//... more type information
}
export = Controller;
Of course, you are essentially undertaking far more work writing JavaScript or Coffeescript and then also writing type information in another file - so you may want to make a decision on a per-unit basis about what you are going to write the program in. For example, if you write a tool-kit in Coffeescript, it is easy to write a single .d.ts
file for it - whereas if you write a file here and there in Coffeescript you're going to have a bit of a maintenance nightmare (either creating lots of .d.ts
files or managing a single merged one each time you change one of the parts).
Definition files work best against a stable API.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With