Skip to content

Instantly share code, notes, and snippets.

@mkusher
Last active December 20, 2016 11:33
Show Gist options
  • Save mkusher/946d2958692e712ff60ab03c8a2b1133 to your computer and use it in GitHub Desktop.
Save mkusher/946d2958692e712ff60ab03c8a2b1133 to your computer and use it in GitHub Desktop.
TypeScript typings example for cucumber
import { World } from "support/World";
export namespace cucumber {
type Step = RegExp|string;
interface StepCallback extends Function {
(this: World, ...args: any[]): void|Promise<any>;
}
export interface Feature {
Given(step: Step, callback: StepCallback): void;
When(step: Step, callback: StepCallback): void;
Then(step: Step, callback: StepCallback): void;
After(callback: Function): void;
Before(callback: Function): void;
}
export interface FeatureContext {
(this: Feature): void;
}
export interface Callback {
(err?: any, type?: string): void;
}
export interface Table {
hashes<T>(): T[];
rows(): string[][];
raw(): string[][];
rowsHash(): { [key: string]: string };
rowsHash<T>(): T;
}
}
import { cucumber } from "somewhere"; // or you could add it to global namespace
const steps: cucumber.FeatureContext = function() {
// here this has type Feature from cucumber namespace
this.Given("test", function() {
// here this has type World
});
};
export default steps;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment