File tree Expand file tree Collapse file tree 2 files changed +12
-7
lines changed Expand file tree Collapse file tree 2 files changed +12
-7
lines changed Original file line number Diff line number Diff line change @@ -675,11 +675,7 @@ declare namespace Sinon {
675675 * An exception is thrown if the property is not already a function.
676676 * The original function can be restored by calling object.method.restore(); (or stub.restore();).
677677 */
678- < T , K extends keyof T > (
679- obj : T ,
680- method : K ,
681- ) : T [ K ] extends ( ...args : infer TArgs ) => infer TReturnValue ? SinonStub < TArgs , TReturnValue >
682- : SinonStub ;
678+ < T , K extends keyof T > ( obj : T , method : K ) : SinonStubbedFunction < T [ K ] > ;
683679 }
684680
685681 interface SinonExpectation extends SinonStub {
@@ -1482,6 +1478,13 @@ declare namespace Sinon {
14821478 type SinonStubbedMember < T > = T extends ( ...args : infer TArgs ) => infer TReturnValue ? SinonStub < TArgs , TReturnValue >
14831479 : T ;
14841480
1481+ /**
1482+ * Replaces a function type with a Sinon stub.
1483+ */
1484+ type SinonStubbedFunction < T > = T extends ( ...args : infer TArgs ) => infer TReturnValue
1485+ ? SinonStub < TArgs , TReturnValue >
1486+ : SinonStub ;
1487+
14851488 interface SinonFake {
14861489 /**
14871490 * Creates a basic fake, with no behavior
Original file line number Diff line number Diff line change @@ -882,16 +882,18 @@ function testTypedStub() {
882882 }
883883 let stub : sinon . SinonStub < [ number , string ] , boolean > = sinon . stub ( ) ;
884884 let stub2 = sinon . stub < [ number , string ] , boolean > ( ) ;
885+ let stub3 : sinon . SinonStubbedFunction < Foo [ "bar" ] > ;
885886 const foo = new Foo ( ) ;
886887 stub = sinon . stub ( foo , "bar" ) ;
887888 stub2 = sinon . stub ( foo , "bar" ) ;
889+ stub3 = sinon . stub ( foo , "bar" ) ;
888890 const result : boolean = stub ( 42 , "qux" ) ;
889891 const fooStub : sinon . SinonStubbedInstance < Foo > = {
890892 bar : sinon . stub ( ) ,
891893 } ;
892894
893- const stub3 = sinon . stub < readonly [ number , string ] , boolean > ( ) ;
894- stub3 . firstCall . args ; // $ExpectType readonly [number, string]
895+ const stub4 = sinon . stub < readonly [ number , string ] , boolean > ( ) ;
896+ stub4 . firstCall . args ; // $ExpectType readonly [number, string]
895897}
896898
897899function testMock ( ) {
You can’t perform that action at this time.
0 commit comments