【发布时间】:2020-06-08 01:27:42
【问题描述】:
我需要将我的types 放在一个单独的文件中,在其中创建它并将其导出为默认值,如下所示:
type props = {
playerId: string;
isAutoplayPrevented: boolean;
}
// 'props' is not defined.eslint(no-undef)
export default props;
虽然我已经定义了props,但我收到了一个 ESLint 警告,指出props 是undefined。
我是否应该忽略该警告并停止 ESLint 投诉,如下所示:// eslint-disable-next-line no-undef
或者还有其他更合适的解决方案吗?
【问题讨论】:
-
还要检查您的 linter 版本,因为这个 TS 功能(仅类型导入和导出语法)是相当新的(TS >= 3.8)。我在最新版本
"typescript": "^3.8.2"、"eslint": "^6.8.0"、"@typescript-eslint/eslint-plugin": "^2.20.1-alpha.5"中没有收到该警告,尽管在使用该类型设置变量时出现了另一个关于"error 'props' is defined but never used no-unused-vars"的错误。
标签: javascript reactjs typescript types