Skip to content

@rotki/no-unknown-parameters ​

Disallow function parameters annotated unknown outside error handling and type guards

📖 Rule Details ​

A parameter typed unknown moves the parsing to the callee, and usually to a cast a few lines later. The value crossed a boundary somewhere, and that boundary is where the schema belongs: parse it there and give this function the named type.

The rule reads the written annotation, so it needs no type information. It reports unknown and any union containing it, on function declarations and expressions, arrow functions, method and call signatures, and constructor parameter properties. unknown[] is not reported, since the annotation states a collection rather than an unparsed value.

Three exemptions are built in:

  • Rejection handlers: any parameter of a callback passed to .catch(), or of the second argument to .then(), whatever it is named. This is not cosmetic: @typescript-eslint/use-unknown-in-catch-callback-variable requires unknown there, so reporting it would put the two rules in direct conflict.
  • Error-handling names: cause, e, err, error and reason, wherever they appear, for helpers that receive a caught value outside a .catch() callback.
  • Type-predicate subjects: function isAccount(value: unknown): value is Account has to accept unknown to be worth writing.

⚙️ Options ​

json
{
  "@rotki/no-unknown-parameters": ["error", { "allowNames": ["raw"] }]
}
  • allowNames (string[], default []): extra parameter names that may be annotated unknown, for a decoding boundary that genuinely takes raw input. The names are added to the built-in error-handling names, which stay allowed.

    Before v1.10.0 this option replaced the error-handling names instead of adding to them. A config that repeated those names to keep them still works; it can now drop them.

🚀 Version ​

This rule was introduced in @rotki/eslint-plugin v1.6.0

🔍 Implementation ​