小编gal*_*h92的帖子

TS Jest 不会接受 NodeJS 16 和 TypeScript 的顶级等待

我正在尝试将我的 NodeJS 12 和 TypeScript 应用程序更新到 Node16,原因之一是需要使用顶级等待。

\n

更新后代码可以正确编译,但 Jest 不会接受特定的顶级等待代码:

\n
ts-jest[ts-compiler] (WARN) src/xxx.ts:11:17 - error TS1378: Top-level \'await\' expressions are only allowed when the \'module\' option is set to \'es2022\', \'esnext\', \'system\', or \'nodenext\', and the \'target\' option is set to \'es2017\' or higher.\n\n11 const project = await client.getProjectId();\n                   ~~~~~\n FAIL  src/xxx.test.ts\n  \xe2\x97\x8f Test suite failed to run\n\n    Jest encountered an unexpected token\n
Run Code Online (Sandbox Code Playgroud)\n

包.json:

\n
ts-jest[ts-compiler] (WARN) src/xxx.ts:11:17 - error TS1378: Top-level \'await\' expressions are only allowed …
Run Code Online (Sandbox Code Playgroud)

node.js typescript jestjs top-level-await

25
推荐指数
1
解决办法
6865
查看次数

React useState 导致双重渲染

考虑规范useState示例:

import React, { useState } from 'react';

const MyComponent = () => {
  const [count, setCount] = useState(0);
  console.log(count);
  return (
    <div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center' }}>
      count: {count}
      <button onClick={() => setCount(count + 1)}>Increment</button>
    </div>
  );
};

export default MyComponent;
Run Code Online (Sandbox Code Playgroud)

单击该按钮可使每个状态打印两次。这是为什么?

短屏幕

reactjs react-hooks

8
推荐指数
1
解决办法
2886
查看次数

使用 {fmt} 和 source_location 创建基于可变参数模板的日志功能

我想在 C++ 中创建一个简单的日志函数,它将代码位置添加到日志消息中。我想避免使用宏以及__FILE__&的使用__LINE__

请注意,该format字符串始终是编译时字符串,我希望在编译时进行尽可能多的计算(目标机器是一个小型 MCU)。

我可以source_location通过experimental/source_location. 我也可以使用{fmt}

我从这个开始。目前,我有以下几点:

#include <fmt/format.h>
#include <experimental/source_location>

using source_location = std::experimental::source_location;

void vlog(fmt::string_view format, fmt::format_args args)
{
  fmt::vprint(format, args);
}

template <typename S, typename... Args>
void log(const S& format, const source_location& location, Args&&... args)
{
  vlog(format, fmt::make_args_checked<fmt::string_view, uint32_t, Args...>(format, location.file_name(), location.line(), args...));
}

#define MY_LOG(format, ...) log(FMT_STRING("{},{}, " format), source_location::current(), __VA_ARGS__)

int main() {
  MY_LOG("invalid squishiness: {}", 42);
}

Run Code Online (Sandbox Code Playgroud)

哪个产量正确./example.cpp,20, …

c++ default-arguments variadic-templates fmt

7
推荐指数
1
解决办法
623
查看次数

在远程服务器上使用 VSCode 资源管理器(使用 SSH)

我需要使用 SSH 在远程服务器中编码/编辑文件,我想使用 VSCode 访问它。

我在 Windows 10 上,在 VSCode 中使用“Git Bash”作为集成终端,这意味着我可以使用 VSCode 的终端连接到服务器。
我缺少的是一种将文件从终端打开到编辑器的方法,甚至更好 - 使用资源管理器与文件交互。

如何才能做到这一点?

visual-studio-code

5
推荐指数
1
解决办法
6135
查看次数

R预测警告

正在做:
predictions <- predict(lm.sqrtFlatprices, interval='prediction', level = 0.68) ^ 2

我得到:
predictions on current data refer to _future_ responses

为什么会出现此警告,我该如何加以抑制?

r predict

5
推荐指数
1
解决办法
1278
查看次数

在 GitHub Actions 中缓存通过 CMake FetchContent 获取的源代码

我有一个基于 CMake 的项目,其中我严重依赖FetchContent来检索多个库(源代码)。下载所有库可能需要一些时间,我想在 CI 运行器上进行编译时节省时间(GitHub Actions)。

我看到有一个缓存操作,如何使用它来缓存获取的源代码?

作为奖励,缓存这些获取的库的​​编译代码也可能会有所帮助。有可能吗?

cmake github-actions

5
推荐指数
0
解决办法
1192
查看次数

mypy:无类型装饰器使 FastAPI 路由的“main”函数无类型

考虑以下:

@app.post("/")
def main(body: RequestBody) -> dict[str, object]:
    pass
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

无类型装饰器使函数“main”无类型 [misc]mypy(error)

在网上找不到任何有关它的信息。我缺少什么?谢谢

python mypy fastapi

5
推荐指数
1
解决办法
1165
查看次数

从 .NET Core 中的 C# 访问“.csproj”属性

我的.csproj文件包含:

...
<PackageId>MyProject</PackageId>
<Version>1.0.0</Version>
...
Run Code Online (Sandbox Code Playgroud)

我如何从我的项目代码中访问它?

csproj .net-core

4
推荐指数
1
解决办法
2135
查看次数

使用React内联自定义`::-webkit-scrollbar`

如何::-webkit-scrollbar在React中使用内联样式将伪元素应用于组件?

css inline scrollbar reactjs

4
推荐指数
2
解决办法
3777
查看次数

在不更改 Terraform 的情况下将新的容器修订版部署到 Cloud Run

我正在为涉及 Cloud Run 的 GCP 项目设置 CI&CD 环境。虽然通过 Terraform 设置一切都非常简单,但我不知道如何在代码更改时更新环境。

文档

  1. 更改配置文件。

但这将应用程序部署与 terraform 配置耦合在一起,而 terraform 配置应该只负责基础设施部署。

理想情况下,我使用 terraform 来配置基础设施,并使用另一个 CI 步骤来构建和部署容器。

这里有最佳实践吗?

相关来源:1

google-cloud-platform terraform terraform-provider-gcp google-cloud-run

4
推荐指数
1
解决办法
2608
查看次数