1. // jQuery.d.ts
    2. // 定义全局变量
    3. declare var $: (param: () => void) => void
    4. // 定义全局函数
    5. interface JqueryInstance {
    6. html: (html: string) => JqueryInstance
    7. }
    8. // 函数重载
    9. declare function $(param: () => void): void
    10. declare function $(param: string): {
    11. html: (html: string) => {}
    12. }
    13. // 使用 interface的语法,实现函数重载
    14. interface JQuery {
    15. (readyFunc: () => void): void
    16. (selector: string): JqueryInstance
    17. }
    18. declare var $: JQuery
    19. // 如何对对象进行类型定义,以及对类进行类型定义,命名空间嵌套问题
    20. declare namespace $ {
    21. namespace fn {
    22. class init
    23. }
    24. }
    1. $(function () {
    2. $('body').html('<div>123</div>')
    3. })
    4. $(function () {
    5. $('body').html('<div>123</div>')
    6. new $.fn.init()
    7. })