Files
DefinitelyTyped/types/saywhen/index.d.ts
Jonathan Yee 3309325bf7 (jasmine) Type safe method names list on a generic for CreateSpyObj (#29325)
⬆ upgrade to TS 2.3 for all dependency. 👽 Use keyof feature only available on 2.3. These changes
allow the array of method names used to be type safe to the properties of the generic class
specified <T>. Although keyof provides non-methods, which isn't allowed by CreateSpyObj, atleast
this provides better typing for users when autocompleting list of class methods (especially if there
are heaps!)
2018-10-01 21:03:28 -07:00

39 lines
883 B
TypeScript

// Type definitions for saywhen 1.1
// Project: https://github.com/pushtechnology/saywhen
// Definitions by: Sean Sobey <https://github.com/SeanSobey>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
/// <reference types="jasmine" />
type Func = (...args: any[]) => any;
declare function when<T extends Func>(spy: T & jasmine.Spy): CallHandler<T>;
declare namespace when {
function captor<T>(val?: T): MatcherProxy<T>;
function noConflict(): void;
function is<T>(val: T): boolean;
}
interface CallHandler<T extends Func> {
readonly isCalled: Proxy<T>;
isCalledWith(...args: any[]): Proxy<T>;
}
interface Proxy<T extends Func> {
then(fn: T): Proxy<T>;
thenReturn(val: any): Proxy<T>;
thenThrow(err: Error): Proxy<T>;
}
interface MatcherProxy<T> {
(arg: T): boolean;
readonly latest: T;
values(): T[];
}
export = when;