Skip to content

no-inferrable-types

JavaScript / TypeScriptstyleno fixdefault: off

Reports a type annotation on a variable, parameter or class property whose initial value already gives that type (const a: number = 5, s: string = 'x', b: boolean = true, n: bigint = 1n). A value from a call, a readonly property and an optional property are not reported.

The compiler infers the same type from the value, so the annotation only adds a second place to keep in sync.

To fix, drop the annotation.

Reported
let a: "a" = "a", b: "a" = 'a', c: 1 = 1, d: string = "a";
...
js:
lint:
rules:
no-inferrable-types: warn # off (default), warn, error

Suppress one line with sudsy-disable-next-line no-inferrable-types in a comment of the file’s language.

The same check in other tools. full: Sudsy reports what the upstream rule reports; partial: only part of it, as the last column says.

Tool Rule Match What differs
typescript-eslint no-inferrable-types partial the options (ignoreParameters, ignoreProperties) keep their defaults