From 50e3756d530572a85766b93a8e0b48672d237156 Mon Sep 17 00:00:00 2001 From: Dimitri Benin Date: Wed, 28 Nov 2018 17:54:31 +0100 Subject: [PATCH 1/2] rename non-node package twitter to twitter-for-web --- types/{twitter => twitter-for-web}/index.d.ts | 0 types/{twitter => twitter-for-web}/tsconfig.json | 0 types/{twitter => twitter-for-web}/tslint.json | 0 types/{twitter => twitter-for-web}/twitter-tests.ts | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename types/{twitter => twitter-for-web}/index.d.ts (100%) rename types/{twitter => twitter-for-web}/tsconfig.json (100%) rename types/{twitter => twitter-for-web}/tslint.json (100%) rename types/{twitter => twitter-for-web}/twitter-tests.ts (100%) diff --git a/types/twitter/index.d.ts b/types/twitter-for-web/index.d.ts similarity index 100% rename from types/twitter/index.d.ts rename to types/twitter-for-web/index.d.ts diff --git a/types/twitter/tsconfig.json b/types/twitter-for-web/tsconfig.json similarity index 100% rename from types/twitter/tsconfig.json rename to types/twitter-for-web/tsconfig.json diff --git a/types/twitter/tslint.json b/types/twitter-for-web/tslint.json similarity index 100% rename from types/twitter/tslint.json rename to types/twitter-for-web/tslint.json diff --git a/types/twitter/twitter-tests.ts b/types/twitter-for-web/twitter-tests.ts similarity index 100% rename from types/twitter/twitter-tests.ts rename to types/twitter-for-web/twitter-tests.ts From f226675f0576e0253c1aaf19ed7395aae27a5961 Mon Sep 17 00:00:00 2001 From: Dimitri Benin Date: Wed, 28 Nov 2018 18:04:33 +0100 Subject: [PATCH 2/2] Add types for twitter, fix twitter-for-web --- types/twitter-for-web/tsconfig.json | 4 +- ...tter-tests.ts => twitter-for-web-tests.ts} | 0 types/twitter/index.d.ts | 69 ++++++++++++++++++ types/twitter/tsconfig.json | 23 ++++++ types/twitter/tslint.json | 1 + types/twitter/twitter-tests.ts | 70 +++++++++++++++++++ 6 files changed, 165 insertions(+), 2 deletions(-) rename types/twitter-for-web/{twitter-tests.ts => twitter-for-web-tests.ts} (100%) create mode 100644 types/twitter/index.d.ts create mode 100644 types/twitter/tsconfig.json create mode 100644 types/twitter/tslint.json create mode 100644 types/twitter/twitter-tests.ts diff --git a/types/twitter-for-web/tsconfig.json b/types/twitter-for-web/tsconfig.json index f57f1c2156..4d4c648e4c 100644 --- a/types/twitter-for-web/tsconfig.json +++ b/types/twitter-for-web/tsconfig.json @@ -19,6 +19,6 @@ }, "files": [ "index.d.ts", - "twitter-tests.ts" + "twitter-for-web-tests.ts" ] -} \ No newline at end of file +} diff --git a/types/twitter-for-web/twitter-tests.ts b/types/twitter-for-web/twitter-for-web-tests.ts similarity index 100% rename from types/twitter-for-web/twitter-tests.ts rename to types/twitter-for-web/twitter-for-web-tests.ts diff --git a/types/twitter/index.d.ts b/types/twitter/index.d.ts new file mode 100644 index 0000000000..dd962eb2cf --- /dev/null +++ b/types/twitter/index.d.ts @@ -0,0 +1,69 @@ +// Type definitions for twitter 1.7 +// Project: https://github.com/desmondmorris/node-twitter +// Definitions by: BendingBender +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 + +/// + +import request = require('request'); +import { EventEmitter } from 'events'; + +export = Twitter; + +declare class Twitter { + readonly VERSION: string; + readonly allow_promise: boolean; + readonly request: typeof request; + + constructor(options: Twitter.AccessTokenOptions | Twitter.BearerTokenOptions); + + get(path: string, params: Twitter.RequestParams, callback: Twitter.Callback): void; + get(path: string, callback: Twitter.Callback): void; + get(path: string, params?: Twitter.RequestParams): Promise; + + post(path: string, params: Twitter.RequestParams, callback: Twitter.Callback): void; + post(path: string, callback: Twitter.Callback): void; + post(path: string, params?: Twitter.RequestParams): Promise; + + stream( + method: 'user' | 'site' | string, + params: { [key: string]: any }, + callback: (stream: EventEmitter) => void + ): void; + stream(method: 'user' | 'site' | string, callback: (stream: EventEmitter) => void): void; + stream(method: 'user' | 'site' | string, params?: { [key: string]: any }): EventEmitter; +} + +declare namespace Twitter { + interface Options { + consumer_key: string; + consumer_secret: string; + rest_base?: string; + stream_base?: string; + user_stream_base?: string; + site_stream_base?: string; + media_base?: string; + request_options?: request.CoreOptions; + } + + interface AccessTokenOptions extends Options { + access_token_key: string; + access_token_secret: string; + } + + interface BearerTokenOptions extends Options { + bearer_token: string; + } + + type Callback = (error: any, data: ResponseData, response: request.Response) => void; + + interface RequestParams { + [key: string]: any; + base?: string; + } + + interface ResponseData { + [key: string]: any; + } +} diff --git a/types/twitter/tsconfig.json b/types/twitter/tsconfig.json new file mode 100644 index 0000000000..919ff67515 --- /dev/null +++ b/types/twitter/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", + "twitter-tests.ts" + ] +} diff --git a/types/twitter/tslint.json b/types/twitter/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/twitter/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } diff --git a/types/twitter/twitter-tests.ts b/types/twitter/twitter-tests.ts new file mode 100644 index 0000000000..1d96ad760a --- /dev/null +++ b/types/twitter/twitter-tests.ts @@ -0,0 +1,70 @@ +import Twitter = require('twitter'); +import { EventEmitter } from 'stream'; + +let client = new Twitter({ + consumer_key: '', + consumer_secret: '', + access_token_key: '', + access_token_secret: '', + site_stream_base: '', +}); +client = new Twitter({ + consumer_key: '', + consumer_secret: '', + bearer_token: '', + site_stream_base: '', +}); + +client.get('favorites/list', (error, tweets, response) => { + if (error) throw error; + // $ExpectType ResponseData + tweets; + // $ExpectType Response + response; +}); + +client.post('statuses/update', { status: 'I Love Twitter' }, (error, tweet, response) => { + if (error) throw error; + // $ExpectType ResponseData + tweet; + // $ExpectType Response + response; +}); + +client.post('statuses/update').then(tweet => { + // $ExpectType ResponseData + tweet; +}); + +client.post('statuses/update', { status: 'I Love Twitter' }).then(tweet => { + // $ExpectType ResponseData + tweet; +}); + +let stream: EventEmitter = client.stream('statuses/filter', { track: 'javascript' }); +stream = client.stream('statuses/filter'); + +stream.on('data', event => { + console.log(event && event.text); +}); + +stream.on('error', error => { + throw error; +}); + +client.stream('statuses/filter', { track: 'javascript' }, stream => { + // $ExpectType EventEmitter + stream; + + stream.on('data', (event: any) => { + console.log(event && event.text); + }); + + stream.on('error', (error: any) => { + throw error; + }); +}); +client.stream('statuses/filter', stream => { + // $ExpectType EventEmitter + stream; +});