Skip to content
Anton edited this page Aug 10, 2019 · 24 revisions

An argument can be specified in a number of ways. The examples below show the source code and how it is rendered by Documentary:

  1. In the body of the constructor or interface elements in XML, and its methods:

    <types>
      <interface name="Example"
        desc="Specifying arguments to a constructor of an interface.">
    
        <!-- arguments to constructors/interfaces will be
             converted into the `constructor` property. -->
        <arg boolean name="wiki">Whether compiling a Wiki page.</arg>
    
        <!-- Functions that the type has can be written as
             fn/function/static -->
        <static async name="upload">
          <arg opt type="string" name="dest">Where to upload.</arg>
          Uploads data to the server.
        </static>
    
      </interface>
    </types>
    Example: Specifying arguments to a constructor of an interface.
    Name Type & Description
    constructor new (wiki: boolean) => Example
    Constructor method.
    wiki* boolean: Whether compiling a Wiki page.
    static upload (dest?: string) => !Promise
    Uploads data to the server.
    dest string (optional): Where to upload.

  2. In the body of a function of a type, or in its arguments:

    <types>
      <type name="FnExample" desc="A non-instantiable record type.">
    
        <!-- The arguments must come before the description of
             the function. -->
        <fn async name="getData" return="{ data: string }">
          <arg string name="source">
            The source from which to extract.
          </arg>
          Requests the data from the server.
        </fn>
        <!-- If arguments were simply given as args, their names
             will be generated, and no description available. -->
        <function args="Array<string>, number="
          name="transform" return="string">
          Transforms given string.
        </function>
      </type>
    </types>
    FnExample: A non-instantiable record type.
    Name Type & Description
    getData* (source: string) => !Promise<{ data: string }>
    Requests the data from the server.
    source* string: The source from which to extract.
    transform* (arg0: Array<string>, arg1?: number) => string
    Transforms given string.

  3. In the body of a method:

    <types namespace="wiki">
    
      <method async name="workHard" desc="Spawns a worker process.">
        <arg number name="hours">How long to work for.</arg>
        <arg type="wiki.Location" name="location">Where to work.</arg>
      </method>
    
      <type name="Location">
        <prop number name="lat" />
        <prop number name="long" />
      </type>
    </types>

    async workHard(
      hours: number,
      location: wiki.Location,
    ): void

    Spawns a worker process.

    • hours* number: How long to work for.
    • location* wiki.Location: Where to work.
    wiki.Location
    Name Type & Description
    lat* number
    long* number

The actual Arg interface is the following:

Arg: An argument of a constructor or method.

Name Type & Description Initial
name ?string null
The name of the argument.
type string
The type of the argument.
optional boolean false
Whether the argument is optional.
description string
Description of the argument.
Clone this wiki locally