如何删除在全局上下文中定义的声明?



我正在我的项目中使用打字稿库"typescript": "^3.6.0"。 这个库"sort"声明了一个名为origin的变量,这会导致以下代码编译,但在执行时抛出异常:


interface Props {
otherProp: string;
origin: string;
}
function runThis(props: Props) {
const { otherProp } = props;
return otherProp + origin;
}

我遇到的问题:

  • 此代码在执行时失败
  • 这是在现有代码库上的工作,如果不对整个代码库进行大量更改,我就无法更改origin名称
  • 在本地修复它不会阻止其他人在同一代码库上工作时犯此错误。

我正在寻找的解决方案:从全局上下文中删除origin声明。

我相信"起源"在您的函数中不存在。您正在使用对象解构,因此我将尝试:

interface Props {
otherProp: string;
origin: string;
}
function runThis(props: Props) {
const { otherProp, origin } = props;
return otherProp + origin;
}

最新更新