diff --git a/types/localtunnel/index.d.ts b/types/localtunnel/index.d.ts index 38efd5862b..ad91ac6dfb 100644 --- a/types/localtunnel/index.d.ts +++ b/types/localtunnel/index.d.ts @@ -1,42 +1,60 @@ -// Type definitions for localtunnel 1.9 +// Type definitions for localtunnel 2.0 // Project: https://github.com/localtunnel/localtunnel // Definitions by: Vladyslav Khrapov +// Noam Alffasy // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +/// + +import { EventEmitter } from "events"; + export = localtunnel; declare function localtunnel( - port: number, - opt: localtunnel.TunnelConfig, - callback: localtunnel.TunnelCallback + port: number | localtunnel.TunnelConfig & { port: number } +): Promise; + +declare function localtunnel( + opts: localtunnel.TunnelConfig & { port: number }, + callback: localtunnel.TunnelCallback, ): localtunnel.Tunnel; declare function localtunnel( port: number, - callback: localtunnel.TunnelCallback + opts: localtunnel.TunnelConfig +): Promise; + +declare function localtunnel( + port: number, + opts: localtunnel.TunnelConfig, + callback: localtunnel.TunnelCallback, ): localtunnel.Tunnel; declare namespace localtunnel { type TunnelCallback = ( - err: string, + err?: string, tunnel?: Tunnel ) => void; interface TunnelConfig { - host?: string; subdomain?: string; - port?: number; + host?: string; local_host?: string; + local_https?: boolean; + local_cert?: string; + local_key?: string; + local_ca?: string; + allow_invalid_cert?: boolean; } - interface Tunnel { + interface Tunnel extends EventEmitter { url: string; - tunnel_cluster: TunnelCluster; - open(err: string, tunnel?: Tunnel): void; + tunnelCluster: TunnelCluster; + open(cb: ((err: string) => void) | (() => void)): void; close(): void; } - interface TunnelCluster { - domain: string; + interface TunnelCluster extends EventEmitter { + open(): void; } } diff --git a/types/localtunnel/localtunnel-tests.ts b/types/localtunnel/localtunnel-tests.ts index 9d631c65e1..12145019f0 100644 --- a/types/localtunnel/localtunnel-tests.ts +++ b/types/localtunnel/localtunnel-tests.ts @@ -1,10 +1,54 @@ import localtunnel = require('localtunnel'); -let tunnel: localtunnel.Tunnel; +let tunnel: localtunnel.Tunnel | Promise; -tunnel = localtunnel(3000, () => {}); +tunnel = localtunnel(3000); +tunnel = localtunnel({ + subdomain: '', + host: '', + local_host: '', + local_https: true, + local_cert: '', + local_key: '', + local_ca: '', + allow_invalid_cert: true, + port: 3000, +}); +tunnel = localtunnel( + { + subdomain: '', + host: '', + local_host: '', + local_https: true, + local_cert: '', + local_key: '', + local_ca: '', + allow_invalid_cert: true, + port: 3000, + }, + () => {}, +); +tunnel = localtunnel(3000, { + subdomain: '', + host: '', + local_host: '', + local_https: true, + local_cert: '', + local_key: '', + local_ca: '', + allow_invalid_cert: true, +}); tunnel = localtunnel( 3000, - { host: '', local_host: '', port: 3000, subdomain: '' }, - () => {} + { + subdomain: '', + host: '', + local_host: '', + local_https: true, + local_cert: '', + local_key: '', + local_ca: '', + allow_invalid_cert: true, + }, + () => {}, );