Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exports method argument types #502

Merged
merged 1 commit into from
Mar 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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`);
});
});