尝试为lib的打字稿构建环境类型定义

时间:2018-10-12 17:57:26

标签: typescript typescript-typings

我正在尝试为以下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.

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

我在理解所有这些方面都遇到了问题。

有人可以帮助我吗?

最诚挚的问候

1 个答案:

答案 0 :(得分:0)

基于源文件,我将这样编写声明:

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