global.d.ts

  1. // Type definitions for [~THE LIBRARY NAME~] [~OPTIONAL VERSION NUMBER~]
  2. // Project: [~THE PROJECT NAME~]
  3. // Definitions by: [~YOUR NAME~] <[~A URL FOR YOU~]>
  4. /*~ If this library is callable (e.g. can be invoked as myLib(3)),
  5. *~ include those call signatures here.
  6. *~ Otherwise, delete this section.
  7. */
  8. declare function myLib(a: string): string;
  9. declare function myLib(a: number): number;
  10. /*~ If you want the name of this library to be a valid type name,
  11. *~ you can do so here.
  12. *~
  13. *~ For example, this allows us to write 'var x: myLib';
  14. *~ Be sure this actually makes sense! If it doesn't, just
  15. *~ delete this declaration and add types inside the namespace below.
  16. */
  17. interface myLib {
  18. name: string;
  19. length: number;
  20. extras?: string[];
  21. }
  22. /*~ If your library has properties exposed on a global variable,
  23. *~ place them here.
  24. *~ You should also place types (interfaces and type alias) here.
  25. */
  26. declare namespace myLib {
  27. //~ We can write 'myLib.timeout = 50;'
  28. let timeout: number;
  29. //~ We can access 'myLib.version', but not change it
  30. const version: string;
  31. //~ There's some class we can create via 'let c = new myLib.Cat(42)'
  32. //~ Or reference e.g. 'function f(c: myLib.Cat) { ... }
  33. class Cat {
  34. constructor(n: number);
  35. //~ We can read 'c.age' from a 'Cat' instance
  36. readonly age: number;
  37. //~ We can invoke 'c.purr()' from a 'Cat' instance
  38. purr(): void;
  39. }
  40. //~ We can declare a variable as
  41. //~ 'var s: myLib.CatSettings = { weight: 5, name: "Maru" };'
  42. interface CatSettings {
  43. weight: number;
  44. name: string;
  45. tailLength?: number;
  46. }
  47. //~ We can write 'const v: myLib.VetID = 42;'
  48. //~ or 'const v: myLib.VetID = "bob";'
  49. type VetID = string | number;
  50. //~ We can invoke 'myLib.checkCat(c)' or 'myLib.checkCat(c, v);'
  51. function checkCat(c: Cat, s?: VetID);
  52. }