1. 定义全局变量

  1. declare var $:(param:() => void) =>void;

2. 定义全局函数

  1. // 定义一个接口类
  2. interface JqueryInstance {
  3. html:(html:string) => JQueryInstace
  4. }
  5. // 函数重载
  6. declare function $(readyFunc:() => void):void;
  7. declare function $(selector:string):JqueryInstance;
  8. // 使用interface 函数重载
  9. interface Jquery {
  10. (readyFunc:() => void):void;
  11. (selector:string):JqueryInstance;
  12. }
  13. declare var $:Jquery
  14. // 对象方法函数
  15. declare namespace ${
  16. namespace fn {
  17. class init {}
  18. }
  19. }

3. 模块代码的类型描述文件

  1. declare module "jquery" {
  2. // 定义一个接口类
  3. interface JqueryInstance {
  4. html: (html: string) => JQueryInstace;
  5. }
  6. // 函数重载
  7. function $(readyFunc: () => void): void;
  8. function $(selector: string): JqueryInstance;
  9. // 对象方法函数
  10. namespace $ {
  11. namespace fn {
  12. class init {}
  13. }
  14. }
  15. // 导出
  16. export = $
  17. }