@@ -51,8 +51,16 @@ function walk(ctx: Lint.WalkContext, tc: ts.TypeChecker) {
51
51
const leftTypeStr = getBaseTypeOfLiteralType ( leftType ) ;
52
52
const rightType = tc . getTypeAtLocation ( node . right ) ;
53
53
const rightTypeStr = getBaseTypeOfLiteralType ( rightType ) ;
54
- if ( leftTypeStr === "invalid" || rightTypeStr === "invalid" || leftTypeStr !== rightTypeStr ) {
55
- const actualTypes = `, but found ${ getTypeString ( tc , node . left , leftType ) } + ${ getTypeString ( tc , node . right , rightType ) } ` ;
54
+ if (
55
+ leftTypeStr === "invalid" ||
56
+ rightTypeStr === "invalid" ||
57
+ leftTypeStr !== rightTypeStr
58
+ ) {
59
+ const actualTypes = `, but found ${ getTypeString (
60
+ tc ,
61
+ node . left ,
62
+ leftType ,
63
+ ) } + ${ getTypeString ( tc , node . right , rightType ) } `;
56
64
let message = Rule . INVALID_TYPES_ERROR + actualTypes ;
57
65
if ( leftTypeStr === "string" || rightTypeStr === "string" ) {
58
66
message += Rule . SUGGEST_TEMPLATE_LITERALS ;
@@ -66,7 +74,11 @@ function walk(ctx: Lint.WalkContext, tc: ts.TypeChecker) {
66
74
67
75
function getTypeString ( tc : ts . TypeChecker , node : ts . Node , type : ts . Type ) {
68
76
const typeString = tc . typeToString ( type , node ) ;
69
- if ( typeString === "undefined[]" && ts . isArrayLiteralExpression ( node ) && ! node . elements . length ) {
77
+ if (
78
+ typeString === "undefined[]" &&
79
+ ts . isArrayLiteralExpression ( node ) &&
80
+ node . elements . length === 0
81
+ ) {
70
82
// Special case literal "[]" arrays that would otherwise be emitted as undefined[].
71
83
return "[]" ;
72
84
}
0 commit comments