GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • CodeQL documentation
  • CodeQL overview
  • Writing CodeQL queries
  • CodeQL language guides
  • QL language reference
  • CodeQL standard-libraries
  • CodeQL query help
  • CodeQL repository
  • QL publications
  • CodeQL query help for C and C++
  • CodeQL query help for C#
  • CodeQL query help for GitHub Actions
  • CodeQL query help for Go
  • CodeQL query help for Java and Kotlin

This view

  • Original page
  • New address

GeezerVison is showing codeql.github.com — Ineffective parameter type — CodeQL query help documentation

Ineffective parameter type¶

ID: js/ineffective-parameter-type
Kind: problem
Security severity: 
Severity: warning
Precision: high
Tags:
   - quality
   - reliability
   - correctness
   - typescript
Query suites:
   - javascript-code-quality.qls
   - javascript-security-and-quality.qls

Click to see the query in the CodeQL repository

In TypeScript, the parameters of a function signature must have a name and may optionally have a type. A common mistake is to try to omit the name. This means the type is instead seen as the name. As a result, the parameter type will default to any since no type was given.

Parameter names in function signatures are only relevant for documentation purposes but cannot be omitted.

Recommendation¶

Give both a name and type to the parameter, as it cannot be given a type without having a name. Alternatively, if the parameter is intentionally untyped, change its name so it does not coincide with a type name.

Example¶

In the following example, the callback parameter is written as (T) => string, which actually means (T: any) => string and is not useful for type checking or code completion.

function join<T>(items: T[], callback: (T) => string) {
  return items.map(callback).join(", ")
}

Amend this by changing the callback type to (item: T) => string. The parameter name item is only relevant for documentation purposes, but a name is required regardless.

function join<T>(items: T[], callback: (item: T) => string) {
  return items.map(callback).join(", ")
}

Untyped parameters are illegal when compiling with the TypeScript flag --noImplicitAny.

References¶

  • TypeScript Handbook, Functions

  • © GitHub, Inc.
  • Terms
  • Privacy
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.