Documentation tests

Deno supports type-checking your documentation examples.

This makes sure that examples within your documentation are up to date and working.

The basic idea is this:

  1. /**
  2. * # Examples
  3. *
  4. * ```ts
  5. * const x = 42;
  6. *

*/

  1. The triple backticks mark the start and end of code blocks.
  2. If this example was in a file named foo.ts, running `deno test --doc foo.ts` will extract this example, and then type-check it as a standalone module living in the same directory as the module being documented.
  3. To document your exports, import the module using a relative path specifier:

/**

  • Examples

    *
  • ```ts
  • import { foo } from “./foo.ts”;
    1. */
    2. export function foo(): string {
    3. return "foo";
    4. }