Skip to content

Commit

Permalink
exports method argument types, fixes slackapi#483
Browse files Browse the repository at this point in the history
  • Loading branch information
aoberoi committed Mar 14, 2018
1 parent 805dd6f commit 5ce84bb
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export {
WebAPIResultCallback,
} from './WebClient';

export * from './methods';

export {
RTMClient,
RTMClientOptions,
Expand Down
28 changes: 28 additions & 0 deletions test/typescript/sources/method-argument-types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { WebClient, ChatPostMessageArguments } from '../../../dist';

const web = new WebClient('TOKEN');

// calling a method directly with arbitrary arguments should work
web.chat.postMessage({
channel: 'CHANNEL',
text: 'TEXT',
key: 'VALUE',
});

// calling a method directly with underspecified arguments should not work
// typings:expect-error
web.chat.postMessage({
channel: 'CHANNEL',
});

// assigning an object with a specific type that includes arbitrary arguments should not work
const message: ChatPostMessageArguments = {
text: 'TEXT',
channel: 'CHANNEL',
// typings:expect-error
key: 'VALUE',
};

// this is just here to avoid the following error:
// 'message' is declared but its value is never read.
console.log(message);
4 changes: 4 additions & 0 deletions test/typescript/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@ describe('typescript typings tests', () => {
it('should allow WebClient to work without a token', () => {
check([`${__dirname}/sources/webclient-no-token.ts`], `${__dirname}/tsconfig-strict.json`);
});

it('should export method argument types and enforce strictness in the right ways', () => {
check([`${__dirname}/sources/method-argument-types.ts`], `${__dirname}/tsconfig-strict.json`);
});
});

0 comments on commit 5ce84bb

Please sign in to comment.