#13 introduced multiple inconsistencies for me (examples seen below). It is not possible to create code that has no lint errors. (Or maybe I am doing something wrong?)
As @sindresorhus already pointed out variable-declaration
was annoying this clearly has been used and I am not sure why the problems I am pointing out were not found / removed? Do I miss something obvious?
As a fix I would remove the typedef requirement for the ones I pointed out below. Or maybe there is a better solution?
Because of this I checked the other typedef requirements and think they are still useful:
call-signature
arrow-call-signature
property-declaration
member-variable-declaration
Examples
arrow-parameter
import test, {ExecutionContext} from 'ava';
test('1', t => {
t.pass();
});
test('2', (t: ExecutionContext) => {
t.pass();
});
error messages:
ERROR: 3:11 typedef expected arrow-parameter: 't' to have a typedef
ERROR: 7:13 no-unnecessary-type-annotation type annotation is redundant
parameter
function meh(foo: string = 'bar', bar = 'foo'): string {
return foo + bar;
}
error messages:
ERROR: 1:19 no-inferrable-types Type string trivially inferred from a string literal, remove type annotation
ERROR: 1:35 typedef expected parameter: 'bar' to have a typedef
object-destructuring
const testObj = {paramA: 'test', paramB: 15};
function caseA(): string {
const {paramA, paramB} = testObj;
return paramA + String(paramB);
}
function caseB(): string {
const {paramA, paramB}: {paramA: string; paramB: number; } = testObj;
return paramA + String(paramB);
}
error messages:
ERROR: 4:8 typedef expected object-destructuring: '{paramA, paramB}' to have a typedef
ERROR: 9:24 no-unnecessary-type-annotation type annotation is redundant
array-destructuring
const testArr = [1, 2, 3];
function caseA(): number {
const [first, second, third] = testArr;
return first + second + third;
}
function caseB(): number {
const [first, second, third]: number[] = testArr;
return first + second + third;
}
error messages:
ERROR: 4:8 typedef expected array-destructuring: '[first, second, third]' to have a typedef
ERROR: 9:30 no-unnecessary-type-annotation type annotation is redundant