From 951ef11442daac4b5873e84bcfac1b262e75299d Mon Sep 17 00:00:00 2001 From: Leko Date: Thu, 6 Dec 2018 16:29:51 +0900 Subject: [PATCH 1/2] Add type definitions for ghauth 3.2 --- types/ghauth/ghauth-tests.ts | 27 ++++++++++++++++++++++ types/ghauth/index.d.ts | 45 ++++++++++++++++++++++++++++++++++++ types/ghauth/tsconfig.json | 23 ++++++++++++++++++ types/ghauth/tslint.json | 1 + 4 files changed, 96 insertions(+) create mode 100644 types/ghauth/ghauth-tests.ts create mode 100644 types/ghauth/index.d.ts create mode 100644 types/ghauth/tsconfig.json create mode 100644 types/ghauth/tslint.json diff --git a/types/ghauth/ghauth-tests.ts b/types/ghauth/ghauth-tests.ts new file mode 100644 index 0000000000..7757cf24dd --- /dev/null +++ b/types/ghauth/ghauth-tests.ts @@ -0,0 +1,27 @@ +import ghauth, { AuthOptions, TokenData } from "ghauth"; + +// Full +const authOptions1: AuthOptions = { + configName: "awesome", + noSave: true, + authUrl: "https://api.github.com/authorizations", + promptName: "GitHub", + scopes: ["user"], + note: "This token is for my awesome app", + userAgent: "My Awesome App", +}; + +ghauth(authOptions1, (err: Error, authData: TokenData) => { + authData.user; + authData.token; +}); + +// Required +const authOptions2: AuthOptions = { + configName: "awesome", +}; + +ghauth(authOptions2, (err: Error, authData: TokenData) => { + authData.user; + authData.token; +}); diff --git a/types/ghauth/index.d.ts b/types/ghauth/index.d.ts new file mode 100644 index 0000000000..e21afdf3fa --- /dev/null +++ b/types/ghauth/index.d.ts @@ -0,0 +1,45 @@ +// Type definitions for ghauth 3.2 +// Project: https://github.com/rvagg/ghauth +// Definitions by: Leko +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export interface AuthOptions { + configName: string; + + /** + * @default false + */ + noSave?: boolean; + + /** + * @default "https://api.github.com/authorizations" + */ + authUrl?: string; + + /** + * @default "GitHub" + */ + promptName?: string; + + /** + * @default [] + */ + scopes?: ReadonlyArray; + + /** + * @default "Node.js command-line app with ghauth" + */ + note?: string; + + /** + * @default "Magic Node.js application that does magic things with ghauth" + */ + userAgent?: string; +} + +export interface TokenData { + user: string; + token: string; +} + +export default function ghauth(authOptions: AuthOptions, callback: (err: Error, tokenData: TokenData) => void): void; diff --git a/types/ghauth/tsconfig.json b/types/ghauth/tsconfig.json new file mode 100644 index 0000000000..0b946b4ae8 --- /dev/null +++ b/types/ghauth/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "ghauth-tests.ts" + ] +} diff --git a/types/ghauth/tslint.json b/types/ghauth/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/ghauth/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From e8127e09dfdaeaf1f7995f9a5ada2bfdfac936a7 Mon Sep 17 00:00:00 2001 From: Leko Date: Fri, 7 Dec 2018 11:35:23 +0900 Subject: [PATCH 2/2] Move types into a namespace --- types/ghauth/ghauth-tests.ts | 4 ++- types/ghauth/index.d.ts | 68 +++++++++++++++++++----------------- 2 files changed, 39 insertions(+), 33 deletions(-) diff --git a/types/ghauth/ghauth-tests.ts b/types/ghauth/ghauth-tests.ts index 7757cf24dd..56bc0cd1b0 100644 --- a/types/ghauth/ghauth-tests.ts +++ b/types/ghauth/ghauth-tests.ts @@ -1,4 +1,6 @@ -import ghauth, { AuthOptions, TokenData } from "ghauth"; +/// +import ghauth = require("ghauth"); +import { AuthOptions, TokenData } from "ghauth"; // Full const authOptions1: AuthOptions = { diff --git a/types/ghauth/index.d.ts b/types/ghauth/index.d.ts index e21afdf3fa..3d91ab8ef5 100644 --- a/types/ghauth/index.d.ts +++ b/types/ghauth/index.d.ts @@ -3,43 +3,47 @@ // Definitions by: Leko // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -export interface AuthOptions { - configName: string; +declare function ghauth(authOptions: ghauth.AuthOptions, callback: (err: Error, tokenData: ghauth.TokenData) => void): void; - /** - * @default false - */ - noSave?: boolean; +declare namespace ghauth { + interface AuthOptions { + configName: string; - /** - * @default "https://api.github.com/authorizations" - */ - authUrl?: string; + /** + * @default false + */ + noSave?: boolean; - /** - * @default "GitHub" - */ - promptName?: string; + /** + * @default "https://api.github.com/authorizations" + */ + authUrl?: string; - /** - * @default [] - */ - scopes?: ReadonlyArray; + /** + * @default "GitHub" + */ + promptName?: string; - /** - * @default "Node.js command-line app with ghauth" - */ - note?: string; + /** + * @default [] + */ + scopes?: ReadonlyArray; - /** - * @default "Magic Node.js application that does magic things with ghauth" - */ - userAgent?: string; + /** + * @default "Node.js command-line app with ghauth" + */ + note?: string; + + /** + * @default "Magic Node.js application that does magic things with ghauth" + */ + userAgent?: string; + } + + interface TokenData { + user: string; + token: string; + } } -export interface TokenData { - user: string; - token: string; -} - -export default function ghauth(authOptions: AuthOptions, callback: (err: Error, tokenData: TokenData) => void): void; +export = ghauth;