TypeScript Version: 2.2.2
Code
Maybe the same as https://github.com/Microsoft/TypeScript/issues/12794
export function convertAllFloat2Int<T>(json: any): T {
if (typeof json !== "String") {
json = JSON.stringify(json);
}
json = JSON.parse(json, function (key: any, value: any) {
let result = value;
if ($.isNumeric(value)) {
result = ~~value;
}
return result;
});
return json;
}
// A *self-contained* demonstration of the problem follows...
Expected behavior:
No compile error as this is a valid JS code or a hint how to solve this issue
Actual behavior:
The following error message on this line 'if (typeof json !== "String") {' :
Operator '!==' cannot be applied to types '"string" | "number" | "boolean" | "symbol" | "undefined" | "object" | "function"' and '"String"'.
Did you mean typeof json !== "string"? Notice that typeof operator returns string without a capital letter.
The error basically tells you that this comparison is always true, because the return value of typeof is never the string you compare it to.
Most helpful comment
Did you mean
typeof json !== "string"? Notice thattypeofoperator returnsstringwithout a capital letter.The error basically tells you that this comparison is always true, because the return value of
typeofis never the string you compare it to.