【问题标题】:Trying to build ambient type definition for typescript for a lib尝试为 lib 的 typescript 构建环境类型定义
【发布时间】:2018-10-12 17:57:26
【问题描述】:

我正在尝试为 js 库构建环境类型定义,如下所示:https://github.com/kkemple/graphql-auth

这是我的类型,但这似乎没有按预期工作

// Type definitions for graphql-auth
// Project: https://github.com/kkemple/graphql-auth
// Definitions by: Andréas `ScreamZ` H. <https://github.com/ScreamZ/>

export = withAuth;

declare function withAuth(resolve: Resolver): Resolver;
declare function withAuth(scopes: string[], resolver: Resolver): Resolver;

declare type Resolver = (root: any, args: any, context: any, info: any) => any

当我尝试导入 .ts 文件时,我得到resolves to a non-module entity and cannot be imported using this construct.

我知道他们改变了声明命名空间和声明模块系统。

我无法理解所有这些内容。

有人可以帮助我吗?

最好的问候

【问题讨论】:

    标签: typescript typescript-typings


    【解决方案1】:

    根据源文件,我会这样写声明:

    declare module "graphql-auth" {
      export type Resolver = (root: any, args: any, context: any, info: any) => any;
    
      function withAuth(callback: Resolver): Resolver;
      function withAuth(scope: string[], callback: Resolver): Resolver;
    
      export default withAuth;
    }
    

    您可能还需要启用esModuleInterop

    【讨论】:

      猜你喜欢
      • 2014-01-02
      • 2020-08-20
      • 1970-01-01
      • 2021-01-12
      • 1970-01-01
      • 1970-01-01
      • 2018-06-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多