我一直在浏览所有其他有关 react/typescript 项目中相同问题的帖子,但这些帖子都没有对我有用……甚至没有将 noImplicitAny 更改为 false 并将 strict 更改为 false 是 ts.config 或设置“排除”和“typeRoots”。
我试过声明一个模块,我试过把它放在一个 .d.ts 文件中,我试过使用@ts-ignore,我什么都做不了。这让我发疯......有人可以告诉我如何一劳永逸地解决这个问题,以便我可以正确编译它吗?
index.js 文件中有更多相同类型的问题,但是一旦有大量需要抛出相同的问题,但一旦我能够解决这个问题,我应该也能够修复其他问题......
(function(factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['rest/index'], factory);
} else if (typeof module === 'object' && module.exports) {
// CommonJS-like environments that support module.exports, like Node.
module.exports = factory(require('./rest/index')); **<---- ERROR HERE**
}
}(function(restIndex) {
return restIndex;
}));
编辑: Client.js:
var apiKey = process.env.ROCKSET_APIKEY;
var apiServer = process.env.ROCKSET_APISERVER;
var rockset = require('rockset')(apiKey, apiServer);
var getResponseLogger = function(callback) {
return function(error, response, body) {
if(error) {
console.log(error.response.error.text);
callback();
} else {
console.log(response);
callback();
}
}
}
export function getMaxSkill() {
rockset.queries.query({
'sql': {
'query': 'select * from "testCollection"'
}
}, null, getResponseLogger(done))
}
function done() {
console.log('\n\n===done===');
}
应用程序.tsx:
import {getMaxSkill} from './client';
async componentDidMount() {
getMaxSkill();
}
tsconfig
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "preserve",
"typeRoots": [
"../../@types",
"../../node_modules/@types"
]
},
"include": [
"src", "tests/App.test.js"
],
"paths": {
"@material-ui/core": ["./material-ui/src"],
"@material-ui/core/*": ["./material-ui/src/*"],
"@material-ui/lab": ["./material-ui-lab/src"],
"@material-ui/lab/*": ["./material-ui-lab/src/*"],
"@material-ui/styles": ["./material-ui-styles/src"],
"@material-ui/styles/*": ["./material-ui-styles/src/*"],
"@material-ui/system": ["./material-ui-system/src"],
"@material-ui/types": ["./material-ui-types"]
}
}