This project is read-only.

Function Signatures

Topics: Language Specification
Nov 19, 2012 at 9:38 PM

Any plans to introduce signatures for functions?

I've been building some *.d.ts files and I find it to be a pain to declare callback types.  Having to declare the same function signature over and over again is messy. BTW, I love being able to grandfather in existing JS libs using *.d.ts.




dothat(callback:(result:string, err?:string)=>void):void;

dothis(callback:(result:string, err?:string)=>void):void;

dothus(callback:(result:string, err?:string)=>void):void;





funcsig MyCallback:(result:string, err?:string)->void;







Thank you!

Nov 20, 2012 at 4:27 PM

There are a couple feature requests in the issue tracker for better typedefs:

You can do what you want with an interface, though. 

interface MyCallback {
  (result:string, err?: string): void;
function dothat(callback: MyCallback): void {}
Nov 25, 2012 at 5:08 PM

Thank you.  It wasn't obvious from the docs but that's exactly what I was looking for.