Disallows explicit type declarations for variables or parameters initialized to a number, string, or boolean. (no-inferrable-types)
Explicit types where they can be easily inferred may add unnecessary verbosity.
This rule disallows explicit type declarations on parameters, variables and properties where the type can be easily inferred from its value.
This rule has an options object:
{
"ignoreProperties": false,
"ignoreParameters": false
}
When none of the options are truthy, the following patterns are valid:
const foo = 5;
const bar = true;
const baz = "str";
class Foo {
prop = 5;
}
function fn(a = 5, b = true) {}
function fn(a: number, b: boolean, c: string) {}
The following are invalid:
const foo: number = 5;
const bar: boolean = true;
const baz: string = "str";
class Foo {
prop: number = 5;
}
function fn(a: number = 5, b: boolean = true) {}
When set to true, the following pattern is considered valid:
class Foo {
prop: number = 5;
}
When set to true, the following pattern is considered valid:
function foo(a: number = 5, b: boolean = true) {
// ...
}
If you do not want to enforce inferred types.
TypeScript Inference
TSLint: no-inferrable-types