我有一系列数字,我需要确保它们是唯一的.我在互联网上找到了下面的代码片段,它的工作情况很好,直到数组中的数字为零.我发现这个其他脚本在SO上看起来几乎就像它,但它不会失败.
所以为了帮助我学习,有人可以帮我确定原型脚本出错的地方吗?
Array.prototype.getUnique = function() {
var o = {}, a = [], i, e;
for (i = 0; e = this[i]; i++) {o[e] = 1};
for (e in o) {a.push (e)};
return a;
}
Run Code Online (Sandbox Code Playgroud)
我运行了 React Native 项目以及官方文档,并将 TypeScript 添加到了该项目中。当我执行“yarn tsc”时,发生了许多 ESlint 错误,例如:
App.tsx:10:14 - error TS2305: Module '"react"' has no exported member 'Node'.
10 import type {Node} from 'react';
Run Code Online (Sandbox Code Playgroud)
我知道这只是一个 TS 错误,但我很困惑,为什么代码“import type {Node} from 'react';”会产生此错误
tsconfig.json:
{
"compilerOptions": {
"allowJs": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"isolatedModules": true,
"jsx": "react-native",
"lib": ["es2017"],
"moduleResolution": "node",
"noEmit": true,
"strict": true,
"target": "esnext"
},
"exclude": [
"node_modules",
"babel.config.js",
"metro.config.js",
"jest.config.js"
]
}
Run Code Online (Sandbox Code Playgroud)