Skip to content

VarArgs inference overly aggressive when checking JavaScript files. #1617

Closed
@houghtonap

Description

@houghtonap

Search terms

  1. VarArgs inference
  2. javascript files

Expected Behavior

  1. To use the @params to document the method and not infer an VarArgs.

Actual Behavior

  1. Actually, it's not what Typedoc failed to do, it's what it actually did.
    When using arguments in a JavaScript function, Typedoc infers VarArgs onto the end of the method even when an actual argument has not been used, e.g., using arguments.length as opposed to an actual argument arguments[1]. This appears to be a Typedoc issue since using the TypeScript playground indicates that the method has only one argument of type any as expected and correctly didn't apply VarArgs per this statement in the TypeScript documentation. What appears to be at issue with the documentation generated by Typedoc is that any reference to arguments will assume the method/function has , ...args: any[] rather than strictly only when an reference to an actual argument is made, e.g., arguments[1].

Steps to reproduce the bug

typedoc.json

{
  "entryPoints": ["test-class.js"],
  "out": "docs"
}

tsconfig.js

{
  "compilerOptions": {
    "target": "es2020",
    "module": "es2020",
    "allowJs": true,
    "checkJs": true,
    "outDir": "./dist",
    "strict": true,
    "moduleResolution": "node",
    "allowSyntheticDefaultImports": true,
    "esModuleInterop": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true
  }
}

test-class.js

/**
 * This is a test class.
 */
export class test
{
  constructor ( )
  {
    if ( this.constructor === test )
      throw new TypeError( `class is not constructable` ) ;
    return this ;
  }
  /**
   * Determines whether a type instance is an instance of this class.
   * @remarks
   * Some remarks...
   * @param {any} type
   * The instance used.
   * @returns {boolean}
   * |What|Description|
   * |:---|:----------|
   * |`True` |When the instance is of type test class.|
   * |`False`|When the instance is not of type test class.|
   * |`TypeError`|When not enough or extraneous arguments were given.|
   */
    static [ Symbol.hasInstance ] ( type )
    {
      const meth = this[ Symbol.hasInstance ] ;
      const args = meth.length ;
      if ( arguments.length < args )
        throw new TypeError( `too few arguments specified` ) ;
      if ( arguments.length > args )
        throw new TypeError( `too many arguments specified` ) ;
      return type !== null && type !== undefined && type.constructor === test ;
    }
}

Environment

  • Typedoc version: 0.21.2
  • TypeScript version: 4.3.4
  • Node.js version: 12.22.1
  • OS: Windows 7 [which is why I'm limited to node 12.22.1]

Metadata

Metadata

Assignees

No one assigned

    Labels

    no bugThis is expected behavior

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions