配置完成后jest
,node.js
和typescript
脚本npx jest
抛出错误控制台
TypeError: Jest: a transform must export something.
at C:\projects\project-api\node_modules\@jest\transform\build\ScriptTransformer.js:386:19
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async Promise.all (index 0)
at async ScriptTransformer.loadTransformers (C:\projects\project-api\node_modules\@jest\transform\build\ScriptTransformer.js:378:5)
at async createScriptTransformer (C:\projects\project-api\node_modules\@jest\transform\build\ScriptTransformer.js:1105:3)
at async C:\projects\project-api\node_modules\@jest\core\build\TestScheduler.js:283:31
at async Promise.all (index 0)
at async TestScheduler.scheduleTests (C:\projects\project-api\node_modules\@jest\core\build\TestScheduler.js:276:5)
at async runJest (C:\projects\project-api\node_modules\@jest\core\build\runJest.js:387:19)
at async _run10000 (C:\projects\project-api\node_modules\@jest\core\build\cli\index.js:408:7)
Run Code Online (Sandbox Code Playgroud)
开玩笑的配置文件
export default {
roots: [
'<rootDir>/src'
],
testMatch: [
'**/__tests__/**/*.+(ts)',
'**/?(*.)+(test).+(ts)'
],
transform: {
'^.+\\.(ts)$': 'ts-jest'
}
}
Run Code Online (Sandbox Code Playgroud)
我在哪里没有正确配置它?
如何获得主格格式的月份名称?
\nimport { format } from 'date-fns'; \nimport { ru } from 'date-fns/locale';\n\nformat(new Date(), 'MMMM', { locale: ru }); // \xd0\xb8\xd1\x8e\xd0\xbd\xd1\x8f\n
Run Code Online (Sandbox Code Playgroud)\n我怎样才能得到像这样的名字\xd1\x8e\xd0\xb8\xd0\xbd\xd1\x8c
而不是\xd0\xb8\xd1\x8e\xd0\xbd\xd1\x8f
?
我想使用Rust和Actix-Web运行一个 Web 服务器。按照文档中的这些步骤操作后,一切都按预期工作:服务器在端口 8080 上运行。
我遇到的问题是 VSCode 显示错误
将错误悬停在 IDE 中时,工具提示中会显示此错误消息
proc 宏
main
未扩展:无法为 /Users/name/Documents/projects/project-rust/target/debug/deps/libactix_web_codegen-b262af45f63000f3.dylib 创建扩展器:Io(Custom { kind: InvalidData, error: DlOpen { desc: "dlopen (/Users/name/Documents/projects/project-rust/target/debug/deps/libactix_web_codegen-b262af45f63000f3.dylib,0x000A):尝试:'/Users/name/Documents/projects/project-rust/target/debug/deps /libactix_web_codegen-b262af45f63000f3.dylib'(mach-o 文件,但是不兼容的架构(有'arm64',需要'x86_64')),'/usr/local/lib/libactix_web_codegen-b262af45f63000f3.dylib'(没有这样的文件) , '/usr/lib/libactix_web_codegen-b262af45f63000f3.dylib' (没有这样的文件)" } })
环境 - macOS 蒙特利 12.1 (M1)
我见过 youtube 等人使用 rust-analyzer 插件在 VSC 中使用 Rust,他们会显示可选的类型注释,即使它不一定写在代码中。就像我foo(a,b)
在编辑器中输入内容一样,它会自动显示和为淡灰色的foo(a: A, b: B)
位置,可能甚至没有写在文件中,只是视觉提示?很好,但我不知道这是 VSC 还是 rust-analyzer 的功能吗?我的 rust-analyzer 有两个设置 Parameter Hints 和 TypeHints 均设置为启用。:A
:B
我正在尝试验证具有动态数量字段的表单 - 即,数据从确定显示多少行的 API 返回,并且对于每一行,都有一个必填字段,需要用户为他们选择一个输入进步。
要使用的软件包是 Yup 和 Formik 一起使用。在查看 Yup 教程时,该对象通常是按如下方式构建的:
let userSchema = object({
name: string().required(),
});
Run Code Online (Sandbox Code Playgroud)
定义名称等键的位置。但是,我的密钥需要是动态的,即 field1、field2 等,因为我事先不知道会有多少个。
我想循环遍历我的对象并将一组动态键传递给模式 - 基本上,无论对象有多长,我都有多少个键。
let userSchema = object({
[field1]: string().required(),
[field2]: string().required(),
});
Run Code Online (Sandbox Code Playgroud)
但是,我不确定如何实现这个结果。我可以循环遍历我的对象并尝试构建一组键,例如
let myObject = {}
myKeyObject.forEach((key) => myObject[key] = string().required());
Run Code Online (Sandbox Code Playgroud)
然后传递myKeyObject
给object.shape,但这通常会产生TS错误。有谁知道 Yup 中有任何用于动态表单的实用程序吗?除非我遗漏了某些内容,否则我在文档中没有看到任何可以使使用动态表单变得更容易的内容
更新apollo-server
到版本3后,控制台中显示以下错误
C:\projects\my_project\node_modules\apollo-server-core\src\ApolloServer.ts:554
throw new Error(
^
Error: You must `await server.start()` before calling `server.applyMiddleware()`
at ApolloServer.assertStarted (C:\projects\my_project\node_modules\apollo-server-core\src\ApolloServer.ts:554:13)
at ApolloServer.applyMiddleware (C:\projects\my_project\node_modules\apollo-server-express\src\ApolloServer.ts:60:10)
at Object.<anonymous> (C:\projects\my_project\src\index.ts:17:14)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Module.m._compile (C:\projects\my_project\node_modules\ts-node\src\index.ts:1225:23)
at Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Object.require.extensions.<computed> [as .ts] (C:\projects\my_project\node_modules\ts-node\src\index.ts:1228:12)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
[nodemon] app crashed - waiting for file changes before starting...
Run Code Online (Sandbox Code Playgroud)
server.start()
之前添加server.applyMiddleware()
并不能解决问题。有什么建议么?
我想手动创建 Prisma 架构的对象
const order: Order = {
id: '1',
name: 'Name',
price: 99
}
...
// Somewhere in autogenerated file by Prisma
export type Order = {
id: string
name: string
price: Prisma.Decimal
}
Run Code Online (Sandbox Code Playgroud)
但它会抛出一个错误
Type 'number' is not assignable to type 'Decimal'.
Run Code Online (Sandbox Code Playgroud)
如何将javascript转换number
为PrismaDecimal
类型?
index.d.ts
lib的文件有express
下一个接口
interface Request<P extends core.Params = core.ParamsDictionary, ResBody = any, ReqBody = any, ReqQuery = core.Query> extends core.Request<P, ResBody, ReqBody, ReqQuery> { }
Run Code Online (Sandbox Code Playgroud)
ResBody
将泛型类型传递给接口的原因是什么Request
?
据我了解,这应该分配给req
中间件的对象
expressMiddleware(
req: Request<{}, ResBody, ReqBody, ReqQuery>,
res: Response<ResBody>,
next: NextFunction,
) {}
Run Code Online (Sandbox Code Playgroud)
但Response
对于这种情况,类型有自己的泛型。
你能帮我解释一下这个问题吗?
我想在我的网站页脚的 package.json 文件中显示声明的版本
我怎样才能做到这一点?
我在他们的文档中找到了这个常见问题解答解释,但不幸的是我不知道从我的组件中访问它
// svelte.config.js
import { readFileSync } from 'fs';
import { fileURLToPath } from 'url';
const file = fileURLToPath(new URL('package.json', import.meta.url));
const json = readFileSync(file, 'utf8');
const pkg = JSON.parse(json);
Run Code Online (Sandbox Code Playgroud) 在 Visual Studio Code 中eslint-plugin-simple-import-sort
应用Format Document
( ) 后是否可以对导入进行排序(通过使用)?Shift+Alt+F
目前,它仅在运行后才起作用eslint --fix
,但我想按文档格式对导入进行排序。
PSFormat document
触发更漂亮