简体   繁体   English

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

[英]Trying to build ambient type definition for typescript for a lib

I'm trying to build a ambient type definition for a js lib which is the following : https://github.com/kkemple/graphql-auth 我正在尝试为下面的js库构建环境类型定义: https : //github.com/kkemple/graphql-auth

here are my types, but this doesn't seems to work as expected 这是我的类型,但这似乎无法正常工作

// 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

When i try to import in a .ts file i'm resulting with resolves to a non-module entity and cannot be imported using this construct. 当我尝试导入.ts文件时,导致resolves to a non-module entity and cannot be imported using this construct.

I know they changed declare namespace and declare module system. 我知道他们更改了声明命名空间和声明模块系统。

I'm having issues understanding all of this. 我在理解所有这些方面遇到了问题。

Can someone helps me ? 有人可以帮我吗?

Best regards 最好的祝福

Based on the source file I would write the declaration like this: 基于源文件,我将这样编写声明:

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;
}

You may need to also enable esModuleInterop . 您可能还需要启用esModuleInterop

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM