Skip to content

Commit

Permalink
Add test for no-unnecesary-type-assertion (palantir#3535)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajafff authored and HyphnKnight committed Apr 9, 2018
1 parent b744dec commit b6dd9e1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions test/rules/no-unnecessary-type-assertion/test.ts.fix
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,10 @@ notATuple;

unknownName;

function foo() {
let xx: 1 | 2 = 1;
const f = () => xx = 2;
f();
xx as 1 | 2 === 2; // xx is inferred as 1, assertion is necessary to avoid compile error
}

7 changes: 7 additions & 0 deletions test/rules/no-unnecessary-type-assertion/test.ts.lint
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,11 @@ declare const notATuple: NotATuple;
unknownName!;
~~~~~~~~~~~~ [0]

function foo() {
let xx: 1 | 2 = 1;
const f = () => xx = 2;
f();
xx as 1 | 2 === 2; // xx is inferred as 1, assertion is necessary to avoid compile error
}

[0]: This assertion is unnecessary since it does not change the type of the expression.

0 comments on commit b6dd9e1

Please sign in to comment.