diff --git a/types/sinon/ts3.1/index.d.ts b/types/sinon/ts3.1/index.d.ts index 920b109281..119ff98137 100644 --- a/types/sinon/ts3.1/index.d.ts +++ b/types/sinon/ts3.1/index.d.ts @@ -626,10 +626,13 @@ declare namespace Sinon { } interface SinonStubStatic { + // Disable rule so assignment to typed stub works (see examples in tests). /** * Creates an anonymous stub function */ - (): SinonStub; + // tslint:disable-next-line no-unnecessary-generics + (): SinonStub; + /** * Stubs all the object’s methods. * Note that it’s usually better practice to stub individual methods, particularly on objects that you don’t understand or control all the methods for (e.g. library dependencies). diff --git a/types/sinon/ts3.1/sinon-tests.ts b/types/sinon/ts3.1/sinon-tests.ts index a420d9851d..2aae56dfdc 100644 --- a/types/sinon/ts3.1/sinon-tests.ts +++ b/types/sinon/ts3.1/sinon-tests.ts @@ -483,6 +483,23 @@ function testStub() { stub.withArgs('a', 2).returns(true); } +function testTypedStub() { + class Foo { + bar(baz: number, qux: string): boolean { + return true; + } + } + let stub: sinon.SinonStub<[number, string], boolean> = sinon.stub(); + let stub2 = sinon.stub<[number, string], boolean>(); + const foo = new Foo(); + stub = sinon.stub(foo, 'bar'); + stub2 = sinon.stub(foo, 'bar'); + const result: boolean = stub(42, 'qux'); + const fooStub: sinon.SinonStubbedInstance = { + bar: sinon.stub() + }; +} + function testMock() { const obj = {}; const mock = sinon.mock(obj);