首页 > 解决方案 > 如何删除在全局上下文中定义的声明?

问题描述

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


interface Props {
  otherProp: string;
  origin: string;
}

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

我遇到的问题:

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

标签: javascripttypescript

解决方案


我相信您的功能中不存在“起源”。您正在使用对象解构,所以我将尝试:

interface Props {
  otherProp: string;
  origin: string;
}

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

推荐阅读