【问题标题】:FaunaDB: How should Document type be imported?FaunaDB:文档类型应该如何导入?
【发布时间】:2021-11-06 09:31:10
【问题描述】:

我想使用在faunadb 值模块中定义的文档类型。但是,TypeScript 编译器无法识别包括 Document 在内的值模块类型导出。

我不能:

import {values} from "faunadb";

const { Document } = values;

我还有其他方法吗?

对于那些不了解 Fauna,但可能对他们的类型导出知识有所帮助的人,Document typescript 类型导出如下:

export module values {

  ...

  export type Document<T = object> = {
    ref: Ref
    ts: number
    data: T
  }

  ...

}

【问题讨论】:

    标签: typescript node-modules faunadb


    【解决方案1】:

    当你这样做时:

    const { Document } = values;
    

    您尝试像使用值一样使用类型。不过,您可以通过 values 模块使用 Document 类型:

    type UserDocument = values.Document<{
      name: string
      email: string
    }>
    
    const result = await client.query<UserDocument>(
      Get(Ref(Collection("User"), "1234"))
    )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-07-21
      • 2021-09-05
      • 1970-01-01
      • 2021-04-07
      • 2014-09-17
      • 2020-08-31
      • 2020-06-21
      • 2020-08-12
      相关资源
      最近更新 更多