javascript - 如何删除在全局上下文中定义的声明?
问题描述
我"typescript": "^3.6.0"
在我的项目中使用了一个打字稿库。这个库“有点”声明了一个名为 的变量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;
}
推荐阅读
- c# - 使用 DbContext 和 Load 加载到内存中的数据库条目会发生什么情况?
- java - 替代字符串组合不是“+”的字符串
- mysql - 在这种情况下如何重写 COUNT 的正确语句
- javascript - 我想添加一个按钮 onclick 功能,在 javascript 中添加几个 toast
- flutter - 如何使用颤振将列表项放在底部导航中?
- android - 如何按照特殊规则以编程方式缩放和裁剪图像
- nginx - 为什么我在 EKS 中使用 ALB 入口控制器时没有创建目标?
- python - 从父类 PYTHON 继承时出错
- python - Pythons Pandas - 将列中的 Str 对象值转换为浮点数
- javascript - GraphQL NodeJS 错误:提供的用于构建模式的类型之一缺少名称