Skip to content

Commit

Permalink
fix(typescript): update types to reflect client option changes (#815)
Browse files Browse the repository at this point in the history
  • Loading branch information
tcbyrd authored and gr2m committed Mar 16, 2018
1 parent 4800e03 commit 7835bde
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 14 deletions.
41 changes: 34 additions & 7 deletions scripts/templates/index.d.ts.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,45 @@ declare namespace Github {
}

export interface Options {
baseUrl?: string;
timeout?: number;
host?: string;
pathPrefix?: string;
protocol?: string;
port?: number;
proxy?: string;
ca?: string;
headers?: {[header: string]: any};
requestMedia?: string;
agent?: http.Agent;

/**
* @deprecated in version 15.0.0
*/
proxy?: string;
/**
* @deprecated in version 15.0.0
*/
ca?: string;
/**
* @deprecated in version 15.0.0
*/
rejectUnauthorized?: boolean;
/**
* @deprecated in version 15.0.0
*/
family?: number;
agent?: http.Agent;

/**
* @deprecated in version 15.2.0
*/
host?: string;
/**
* @deprecated in version 15.2.0
*/
pathPrefix?: string;
/**
* @deprecated in version 15.2.0
*/
protocol?: string;
/**
* @deprecated in version 15.2.0
*/
port?: number;
}

export interface AuthBasic {
Expand Down
36 changes: 29 additions & 7 deletions test/typescript-validate.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,39 @@
import * as Octokit from '../'
import {Agent} from 'http'
const http = require('http');

// ************************************************************
// THIS CODE IS NOT EXECUTED. IT IS JUST FOR TYPECHECKING
// ************************************************************

// Test the TypeScript definition.
export default async function() {
// ************************************************************
// THIS CODE IS NOT EXECUTED. IT IS JUST FOR TYPECHECKING
// ************************************************************
new Octokit() // Check empty constructor
const octo = new Octokit({}) // Check that all arguments are optional
const repo = await octo.repos.get({owner: 'octokit', repo: 'rest.js'})
// Check empty constructor
new Octokit()

// Check that all arguments are optional
new Octokit({})

// for all supported options
const octokit = new Octokit({
timeout: 0,
requestMedia: 'application/vnd.github.v3+json',
headers: {
'user-agent': 'octokit/rest.js v1.2.3'
},
baseUrl: 'https://api.github.com',
agent: new Agent({ keepAlive: true }),

// deprecated options (see deprecations-test.js)
protocol: 'https',
port: 433,
pathPrefix: '',
proxy: '',
ca: '',
rejectUnauthorized: false,
family: 6
})

const repo = await octokit.repos.get({owner: 'octokit', repo: 'rest.js'})
// Check Response
repo.data
repo.meta.link
Expand Down

0 comments on commit 7835bde

Please sign in to comment.