小编Tob*_* S.的帖子

Actix Web:请求的应用程序数据配置不正确。查看/启用调试日志以获取更多详细信息

我有一个简单的应用程序,带有 HTTP 端点和到 MongoDB 数据库的连接。

use actix_web::{
    middleware, post,
    web::{self},
    App, HttpServer, Responder,
};
use mongodb::{options::ClientOptions, Client};
use serde::Deserialize;

#[derive(Deserialize, Debug)]
struct TestBody {
    name: String,
    age: u8,
}

#[post("/test")]
async fn test(query: web::Json<TestBody>, db: web::Data<Client>) -> impl Responder {
    for db_name in db.list_database_names(None, None).await.unwrap() {
        println!("{}", db_name);
    }

    let res = format!("{} {}", query.name, query.age);
    res
}

#[actix_web::main]
async fn main() -> std::io::Result<()> {
    let connection_string = "secret-connection-string";
    let client_options = ClientOptions::parse(connection_string).await.unwrap();
    let client = Client::with_options(client_options).unwrap();

    HttpServer::new(move || { …
Run Code Online (Sandbox Code Playgroud)

rust actix-web

14
推荐指数
1
解决办法
6329
查看次数

Rust 中的“一揽子实现”是什么?

在查看 Rust 结构体的文档时,我经常会遇到标题为“Blanket Implements”的部分。我听说它可以用来实现所有类型或匹配某些条件的所有类型的特征,但我不确定为什么需要这样做。

那么一揽子实现到底是什么?为什么它们在 Rust 中有用?

rust

13
推荐指数
1
解决办法
4824
查看次数

如何限制数组包含 TypeScript 中枚举的每个成员

enum AllowedFruits {
  Apple = 'APPLE',
  Banana = 'BANANA',
  Pear = 'PEAR'
}

const allowedFruits: AllowedFruits[] = [
  AllowedFruits.Apple, AllowedFruits.Banana, AllowedFruits.Pear
]
Run Code Online (Sandbox Code Playgroud)

我想要实现的是将数组限制为具有特定枚举的每个字段。我期望allowedFruits通过添加或删除 的字段来显示类型错误AllowedFruits

有什么办法可以实现吗?

如果有任何文章或文档可供我参考,请告诉我。

enums typescript mapped-types

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

如何使用顺风发髻

我正在使用Bun.sh创建一个 React 应用程序。

但我也使用 tailwindcss 进行造型,而 tailwind 对于发髻没有官方解决方案。如何将这两者结合使用?

我知道面包还没有准备好生产,但如果可能的话,我仍在寻找解决方案。

reactjs tailwind-css bun

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

如何在 TypeScript 中使用 enum 正确输入 React useState hook

如何正确输入我的 useState 挂钩?

我有这种enum类型:

export enum Status {
  PENDING = 'pending',
  SUCCESS = 'success',
  ERROR = 'error',
}
Run Code Online (Sandbox Code Playgroud)

还有useState钩子:const [isValid, setIsValid] = useState<// What to add here>(ApiStatus.PENDING);

那么useState钩子的值只能是其中一个Status值?

typescript reactjs typescript-typings react-hooks

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

将 @nestjs/mongoose 从 9.0.3 升级到 9.1.0 后出现错误“错误:Nest 无法解析 WatchlistService 的依赖项”

将 @nestjs/mongoose 从 9.0.3 更新到 9.1.0 后,我遇到以下错误:

[Nest] 3818  - 06/04/2022, 12:50:13 AM   ERROR [ExceptionHandler] Nest can't resolve dependencies of the WatchlistService (?). Please make sure that the argument PortfolioModel at index [0] is available in the AppModule context.

Potential solutions:
- If PortfolioModel is a provider, is it part of the current AppModule?
- If PortfolioModel is exported from a separate @Module, is that module imported within AppModule?
  @Module({
    imports: [ /* the Module containing PortfolioModel */ ]
  }) …
Run Code Online (Sandbox Code Playgroud)

mongoose nestjs

3
推荐指数
1
解决办法
706
查看次数

RxJS 在 Subscription 内订阅不同数量的 Observable

在下面的代码片段中,我订阅了一个投资组合并遍历一个数组。对于数组的每个成员,我创建另一个订阅来收听其报价。

this.portfolio$
  .subscribe(portfolio) => {
    portfolio.watchlist.all.forEach((a) => {      
        this.store
          .select((s) => s.quotes.quotes[a._id])          
          .subscribe((q) => {
            console.warn('subscription')
          }
      }
    })
  })
Run Code Online (Sandbox Code Playgroud)

是否有任何 RxJS 运算符可以让我摆脱外部订阅?最后,我只想拥有与数组中的引号一样多的订阅。

javascript rxjs typescript ngrx angular

2
推荐指数
1
解决办法
52
查看次数

在打字稿中键入具有最大属性数量的动态键

我想知道是否可以在打字稿中键入对象中动态属性的最大数量。

所以基本的例子是跟踪事件:

events.track('SOME_EVENT', { first: 'a', other: 'b', some: 'c'})
Run Code Online (Sandbox Code Playgroud)

事件数据应该最多保存 3 个属性及其各自的值,键也可以是动态的。

我用 basic 键入它Record,但允许的属性数量没有限制:

export interface Events {
  track: (name: string, params?: Record<string, string | number | unknown>) => void;
}
Run Code Online (Sandbox Code Playgroud)

这可能吗?

javascript types typescript

2
推荐指数
1
解决办法
736
查看次数

A "const" assertion error typescript with string array

I'm trying to learn Typescript with React, but this error got in my way. I don't understand why is it even happening. Here it is. Creating an array of strings that looks like colors array down there. I want to create types based on values of that array ("white" | "red" | "blue").

const colors = ["white", "red", "blue"] as const;
type Colors= typeof colors[number];
Run Code Online (Sandbox Code Playgroud)

If I do it like this, it works, Colors has wanted types

const colorsArr = …
Run Code Online (Sandbox Code Playgroud)

javascript typescript reactjs typescript-typings

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