module-function.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. /*~ This is the module template file for function modules.
  5. *~ You should rename it to index.d.ts and place it in a folder with the same name as the module.
  6. *~ For example, if you were writing a file for "super-greeter", this
  7. *~ file should be 'super-greeter/index.d.ts'
  8. */
  9. /*~ Note that ES6 modules cannot directly export callable functions.
  10. *~ This file should be imported using the CommonJS-style:
  11. *~ import x = require('someLibrary');
  12. *~
  13. *~ Refer to the documentation to understand common
  14. *~ workarounds for this limitation of ES6 modules.
  15. */
  16. /*~ If this module is a UMD module that exposes a global variable 'myFuncLib' when
  17. *~ loaded outside a module loader environment, declare that global here.
  18. *~ Otherwise, delete this declaration.
  19. */
  20. export as namespace myFuncLib;
  21. /*~ This declaration specifies that the function
  22. *~ is the exported object from the file
  23. */
  24. export = MyFunction;
  25. /*~ This example shows how to have multiple overloads for your function */
  26. declare function MyFunction(name: string): MyFunction.NamedReturnType;
  27. declare function MyFunction(length: number): MyFunction.LengthReturnType;
  28. /*~ If you want to expose types from your module as well, you can
  29. *~ place them in this block. Often you will want to describe the
  30. *~ shape of the return type of the function; that type should
  31. *~ be declared in here, as this example shows.
  32. */
  33. declare namespace MyFunction {
  34. export interface LengthReturnType {
  35. width: number;
  36. height: number;
  37. }
  38. export interface NamedReturnType {
  39. firstName: string;
  40. lastName: string;
  41. }
  42. /*~ If the module also has properties, declare them here. For example,
  43. *~ this declaration says that this code is legal:
  44. *~ import f = require('myFuncLibrary');
  45. *~ console.log(f.defaultName);
  46. */
  47. export const defaultName: string;
  48. export let defaultLength: number;
  49. }