简体   繁体   English

“in”表达式的左侧必须是私有标识符或类型为“any”、“string”、“number”或“symbol”

[英]The left-hand side of an 'in' expression must be a private identifier or of type 'any', 'string', 'number', or 'symbol'

How to fix this type error, even that i already define a String type to key parameter.如何修复此类型错误,即使我已经将字符串类型定义为关键参数。

function checkIsExistObjectKeys(object: Object, key: String): Boolean {
  return key in object;
}

console.log(
  checkIsExistObjectKeys(
    {
      name: "john",
      lastName: "Francois",
    },
    "name"
  )
);

在此处输入图像描述

The key parameter should be of type string , not String . key 参数的类型应该是string ,而不是String

function checkIsExistObjectKeys(object: Object, key: string): Boolean {
  return Object.keys(object).some(x => x === key);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 获取错误算术运算的左侧必须是“any”,“number”或枚举类型 - get error The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type 算术运算的左侧必须为“ any”,“ number”或枚举类型。 无法将数字声明为数字 - The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. Can't declare Number as number 打字稿。 如何在foreach循环中避免这个错误:“算术运算的左侧必须是'any','number'或枚举类型”? - Typescript. How to avoid this error in foreach loop: “left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type”? 左侧表达式无效 - Invalid left-hand side expression 赋值表达式中的左侧无效 - Invalid left-hand side in assignment expression 使用 fs.readFileSync 读取 private.key,前缀操作中的左侧表达式无效 - read private.key with fs.readFileSync, nvalid left-hand side expression in prefix operation Typescript - 索引表达式参数必须是'string','number','symbol'或'any'类型 - Typescript - An index expression argument must be of type 'string', 'number', 'symbol' or 'any' 未捕获的ReferenceError:postfix操作中的左侧表达式无效 - Uncaught ReferenceError: Invalid left-hand side expression in postfix operation 前缀操作中的左侧表达式无效 - Invalid left-hand side expression in prefix operation JS后缀操作中的左侧表达式无效? - JS Invalid left-hand side expression in postfix operation?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM