我更新了我的项目以创建 react app 4.0,并且我正在放缓将我的文件移动到 TypeScript。我知道使用这个新版本,您不必重复从“react”导入 React。但是,在我未导入 React 的所有 TS 文件中,我收到此错误'React' refers to a UMD global, but the current file is a module. Consider adding an import instead.ts(2686)。我知道我可以通过导入 React 来修复它,但我认为这不再需要了。另外,有人可以解释这个错误的含义吗?
我的基本 TSX 文件
const Users = () => {
return <>Teachers aka Users</>;
};
export default Users;
Run Code Online (Sandbox Code Playgroud) 我读过许多与我类似的问题,但似乎没有一个能解决我的问题。我正在使用 Vue3、TypeScript、Jest 和 D3 v7。当我尝试时,import * as d3 from "d3";我在测试中收到此错误:
({"Object.<anonymous>":
function(module,exports,require,__dirname,__filename,global,jest)
{export * from "d3-array";
Run Code Online (Sandbox Code Playgroud)
当我这样导入 d3 时也会出现此错误
import { BaseType, Selection, Transition, select } from "d3";
我尝试更新我的笑话配置的transformIgnorePatterns属性以进行读取,但这也不起作用:
transformIgnorePatterns: [
"<rootDir>/node_modules/(?!d3-(array))",
]
Run Code Online (Sandbox Code Playgroud)
有人可以向我解释一下我在这里缺少的部分吗?下面也是我的整个jest.config.js文件
module.exports = {
collectCoverageFrom: [
"**/src/**.ts",
"**/src/**/**.ts",
"!**/dist/**",
"!**/node_modules/**",
"!**/public/**"
],
errorOnDeprecated: true,
preset: "@vue/cli-plugin-unit-jest/presets/typescript",
testMatch: ["**/*.spec.ts", "!**/node_modules/**"],
testPathIgnorePatterns: ["<rootDir>/dist/", "<rootDir>/node_modules/"],
"modulePaths": [
"<rootDir>"
],
transformIgnorePatterns: [
"<rootDir>/node_modules/(?!d3-(array))",
],
transform: {
"^.+\\.ts": "ts-jest",
"^.+\\.vue$": "vue-jest",
},
};
Run Code Online (Sandbox Code Playgroud) 我一直试图解决这个错误一段时间.错误读取Can't resolve all parameters for AngularFirestore: ([object Object], ?).有没有其他人有这个问题,你怎么能解决这个问题.我已经阅读了文档,但我无法理解这个问题.
import { Component } from '@angular/core';
import { AngularFirestore } from 'angularfire2/firestore';
import { AngularFireDatabase } from 'angularfire2/database';
import { Observable } from 'rxjs/Observable';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
providers: [AngularFirestore, AngularFireDatabase]
})
export class AppComponent {
items: Observable<any[]>;
constructor(db: AngularFirestore, adb: AngularFireDatabase) {
this.items = db.collection('0').valueChanges();
console.log(this.items)
}
}
Run Code Online (Sandbox Code Playgroud)
的package.json
"angularfire2": "^5.0.0-rc.3",
"firebase": "^4.6.0",
Run Code Online (Sandbox Code Playgroud) firebase firebase-realtime-database angular google-cloud-firestore
我正在编写一个测试,以确保我的表单使用反应测试库提交,并且我还使用反应挂钩表单。我的提交方法在我的测试中无法调用。当此测试运行时,我收到以下错误:
\n\xe2\x97\x8f reset password should send\n\n expect(jest.fn()).toHaveBeenCalled()\n\n Expected number of calls: >= 1\n Received number of calls: 0\nRun Code Online (Sandbox Code Playgroud)\n有人可以解释我做错了什么吗?
\n我的组件
\nconst ResetPassword = () => {\n const { handleSubmit } = useForm();\n\n const onSubmit = (resetFormData: { email: string }) => {\n const { email } = resetFormData;\n // sends email using external API\n };\n\n return (\n <form onSubmit={handleSubmit(onSubmit)}>\n <input\n name="email"\n type="text"\n placeholder="Email Address"\n />\n <button type="submit">\n Send Email\n </button>\n </form>\n );\n};\n\nexport default ResetPassword;\nRun Code Online (Sandbox Code Playgroud)\n我的测试文件 …
javascript ×2
reactjs ×2
angular ×1
d3.js ×1
firebase ×1
jestjs ×1
ts-jest ×1
typescript ×1
vue.js ×1
vuejs3 ×1