简体   繁体   中英

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

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.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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