diff --git a/types/karma-chai-sinon/index.d.ts b/types/karma-chai-sinon/index.d.ts index 76ee313a40..1ce2672b23 100644 --- a/types/karma-chai-sinon/index.d.ts +++ b/types/karma-chai-sinon/index.d.ts @@ -2,7 +2,7 @@ // Project: https://github.com/tubalmartin/karma-chai-sinon // Definitions by: Václav Ostrožlík // Definitions: https://github.com/borisyankov/DefinitelyTyped -// TypeScript Version: 2.3 +// TypeScript Version: 2.8 /// import Sinon = require("sinon"); diff --git a/types/mochaccino/index.d.ts b/types/mochaccino/index.d.ts index b230218ee9..3f0a2e9688 100644 --- a/types/mochaccino/index.d.ts +++ b/types/mochaccino/index.d.ts @@ -2,7 +2,7 @@ // Project: https://github.com/pawelgalazka/mochaccino#readme // Definitions by: Thomas-P // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.3 +// TypeScript Version: 2.8 import * as Sinon from "sinon"; export interface Expect { not: Expect; diff --git a/types/should-sinon/index.d.ts b/types/should-sinon/index.d.ts index 25233c1c61..467d217aa9 100644 --- a/types/should-sinon/index.d.ts +++ b/types/should-sinon/index.d.ts @@ -2,7 +2,7 @@ // Project: https://github.com/shouldjs/sinon // Definitions by: AryloYeung // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.3 +// TypeScript Version: 2.8 import * as s from "sinon"; import should = require("should"); diff --git a/types/sinon-as-promised/index.d.ts b/types/sinon-as-promised/index.d.ts index 097e13a1a0..49e9b29bd3 100644 --- a/types/sinon-as-promised/index.d.ts +++ b/types/sinon-as-promised/index.d.ts @@ -2,7 +2,7 @@ // Project: https://github.com/bendrucker/sinon-as-promised // Definitions by: igrayson // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.3 +// TypeScript Version: 2.8 import * as s from "sinon"; diff --git a/types/sinon-chai/index.d.ts b/types/sinon-chai/index.d.ts index 8c6d7eb2d0..cff6d0b3a2 100644 --- a/types/sinon-chai/index.d.ts +++ b/types/sinon-chai/index.d.ts @@ -2,7 +2,7 @@ // Project: https://github.com/domenic/sinon-chai // Definitions by: Kazi Manzur Rashid , Jed Mao // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.3 +// TypeScript Version: 2.8 /// /// diff --git a/types/sinon-chrome/index.d.ts b/types/sinon-chrome/index.d.ts index 263135e060..9776b0bb30 100644 --- a/types/sinon-chrome/index.d.ts +++ b/types/sinon-chrome/index.d.ts @@ -4,7 +4,7 @@ // CRIMX // kobanyan // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.4 +// TypeScript Version: 2.8 /// /// diff --git a/types/sinon-express-mock/index.d.ts b/types/sinon-express-mock/index.d.ts index 10c8ef824d..f3974fc005 100644 --- a/types/sinon-express-mock/index.d.ts +++ b/types/sinon-express-mock/index.d.ts @@ -3,7 +3,7 @@ // Definitions by: Jared Chapiewsky // Tomek Łaziuk // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.3 +// TypeScript Version: 2.8 import { SinonStub, diff --git a/types/sinon-mongoose/index.d.ts b/types/sinon-mongoose/index.d.ts index 2d9099a060..86109b4917 100644 --- a/types/sinon-mongoose/index.d.ts +++ b/types/sinon-mongoose/index.d.ts @@ -2,7 +2,7 @@ // Project: https://github.com/underscopeio/sinon-mongoose // Definitions by: stevehipwell // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.3 +// TypeScript Version: 2.8 import * as s from "sinon"; diff --git a/types/sinon-stub-promise/index.d.ts b/types/sinon-stub-promise/index.d.ts index 6de3b17b2a..d817113cf7 100644 --- a/types/sinon-stub-promise/index.d.ts +++ b/types/sinon-stub-promise/index.d.ts @@ -3,7 +3,7 @@ // Definitions by: Thiago Temple // Tim Stackhouse // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.3 +// TypeScript Version: 2.8 /// diff --git a/types/sinon-test/index.d.ts b/types/sinon-test/index.d.ts index 4cda8702a6..902064a7cb 100644 --- a/types/sinon-test/index.d.ts +++ b/types/sinon-test/index.d.ts @@ -2,7 +2,7 @@ // Project: https://github.com/sinonjs/sinon-test // Definitions by: Francis Saul // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.3 +// TypeScript Version: 2.8 import * as Sinon from 'sinon'; diff --git a/types/sinon/index.d.ts b/types/sinon/index.d.ts index 2395ee2ed2..0bc7d112fc 100644 --- a/types/sinon/index.d.ts +++ b/types/sinon/index.d.ts @@ -5,8 +5,9 @@ // Lukas Spieß // Nico Jansen // James Garbutt +// Josh Goldberg // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.3 +// TypeScript Version: 2.8 // sinon uses DOM dependencies which are absent in browser-less environment like node.js // to avoid compiler errors this monkey patch is used @@ -566,15 +567,20 @@ declare namespace Sinon { } /** - * An instance of a stubbed object type with members replaced by stubs. + * An instance of a stubbed object type with functions replaced by stubs. * * @template TType Object type being stubbed. */ type SinonStubbedInstance = { // TODO: this should really only replace functions on TType with SinonStubs, not all properties // Likely infeasible without mapped conditional types, per https://github.com/Microsoft/TypeScript/issues/12424 - [P in keyof TType]: SinonStub; + [P in keyof TType]: SinonStubbedMember; }; + + /** + * Replaces a type with a Sinon stub if it's a function. + */ + type SinonStubbedMember = T extends Function ? SinonStub : T; } declare const Sinon: Sinon.SinonStatic; diff --git a/types/sinon/sinon-tests.ts b/types/sinon/sinon-tests.ts index 17e8cc6084..c6ffc7a51e 100644 --- a/types/sinon/sinon-tests.ts +++ b/types/sinon/sinon-tests.ts @@ -154,6 +154,15 @@ function testSandbox() { sandbox.createStubInstance(TestCreateStubInstance).someTestMethod('some argument'); } +class OneFunctionOneNumber { + memberFunction() { } + memberNumber: number; +} + +const stubInstance = sinon.createStubInstance(OneFunctionOneNumber); +const memberFunction: sinon.SinonStub = stubInstance.memberFunction; +const memberNumber: number = stubInstance.memberNumber; + function testPromises() { let resolveStub = sinon.stub().resolves(); resolveStub = sinon.stub().resolves(10);