diff --git a/test/rules/no-unnecessary-type-assertion/test.ts.fix b/test/rules/no-unnecessary-type-assertion/test.ts.fix index d34e6e5ca52..6bc4afd88e5 100644 --- a/test/rules/no-unnecessary-type-assertion/test.ts.fix +++ b/test/rules/no-unnecessary-type-assertion/test.ts.fix @@ -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 +} + diff --git a/test/rules/no-unnecessary-type-assertion/test.ts.lint b/test/rules/no-unnecessary-type-assertion/test.ts.lint index 6b3a8680fa1..a0068aebfb5 100644 --- a/test/rules/no-unnecessary-type-assertion/test.ts.lint +++ b/test/rules/no-unnecessary-type-assertion/test.ts.lint @@ -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.