简体   繁体   中英

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 .

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM