Skip to content

typescript/no-inferrable-types Style

🚧 An auto-fix is still under development.

What it does

Disallow explicit type declarations for variables or parameters initialized to a number, string, or boolean

Why is this bad?

Explicitly typing variables or parameters that are initialized to a literal value is unnecessary because TypeScript can infer the type from the value.

Examples

Examples of incorrect code for this rule:

ts
const a: number = 5;
const b: string = "foo";
const c: boolean = true;
const fn = (a: number = 5, b: boolean = true, c: string = "foo") => {};

Examples of correct code for this rule:

ts
const a = 5;
const b = "foo";
const c = true;
const fn = (a = 5, b = true, c = "foo") => {};

References

Released under the MIT License.