为什么在当前范围内使用与变量同名的 prop 会被视为阴影?

Why does using a prop with the same name as a variable in the current scope considered shadowing?

我目前正在将 tslint 与 tslint:recommended 一起使用,这意味着不允许使用阴影:

"no-shadowed-variable": true

虽然我明白这意味着什么,但我惊讶地发现以下代码片段不符合此规则:

const createMenuItem = (iconElement, menuItem, showOn) => (
  <SMenuItemContent showOn={showOn}>
    {iconElement}
    {menuItem}
  </SMenuItemContent>
);

具体来说,tslint 指出 showOn 正在被隐藏。转译这段代码时,它看起来像

var createMenuItem = function createMenuItem(iconElement, menuItem, showOn) {
  return React.createElement(
    SMenuItemContent,
    { showOn: showOn },
    iconElement,
    menuItem
  );
};

showOn 是如何被隐藏的?

也许您在更大范围(文件级别)的同一文件上定义了 showOn?。在我看来,它应该可以独立运行。