Skip to content

Commit 89b9e6e

Browse files
committed
Add spy repro from #25181
1 parent 17d37ec commit 89b9e6e

File tree

5 files changed

+223
-0
lines changed

5 files changed

+223
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
tests/cases/compiler/spyComparisonChecking.ts(20,32): error TS2339: Property 'returnValue' does not exist on type 'Function'.
2+
3+
4+
==== tests/cases/compiler/spyComparisonChecking.ts (1 errors) ====
5+
interface Spy {
6+
(...params: any[]): any;
7+
8+
identity: string;
9+
and: Function;
10+
mostRecentCall: { args: any[]; };
11+
argsForCall: any[];
12+
}
13+
14+
type SpyObj<T> = T & {
15+
[k in keyof T]: Spy;
16+
}
17+
18+
declare function createSpyObj<T>(
19+
name: string, names: Array<keyof T>): SpyObj<T>;
20+
21+
function mock<T>(spyName: string, methodNames: Array<keyof T>): SpyObj<T> {
22+
const spyObj = createSpyObj<T>(spyName, methodNames);
23+
for (const methodName of methodNames) {
24+
spyObj[methodName].and.returnValue(1);
25+
~~~~~~~~~~~
26+
!!! error TS2339: Property 'returnValue' does not exist on type 'Function'.
27+
}
28+
return spyObj;
29+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//// [spyComparisonChecking.ts]
2+
interface Spy {
3+
(...params: any[]): any;
4+
5+
identity: string;
6+
and: Function;
7+
mostRecentCall: { args: any[]; };
8+
argsForCall: any[];
9+
}
10+
11+
type SpyObj<T> = T & {
12+
[k in keyof T]: Spy;
13+
}
14+
15+
declare function createSpyObj<T>(
16+
name: string, names: Array<keyof T>): SpyObj<T>;
17+
18+
function mock<T>(spyName: string, methodNames: Array<keyof T>): SpyObj<T> {
19+
const spyObj = createSpyObj<T>(spyName, methodNames);
20+
for (const methodName of methodNames) {
21+
spyObj[methodName].and.returnValue(1);
22+
}
23+
return spyObj;
24+
}
25+
26+
//// [spyComparisonChecking.js]
27+
function mock(spyName, methodNames) {
28+
var spyObj = createSpyObj(spyName, methodNames);
29+
for (var _i = 0, methodNames_1 = methodNames; _i < methodNames_1.length; _i++) {
30+
var methodName = methodNames_1[_i];
31+
spyObj[methodName].and.returnValue(1);
32+
}
33+
return spyObj;
34+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
=== tests/cases/compiler/spyComparisonChecking.ts ===
2+
interface Spy {
3+
>Spy : Symbol(Spy, Decl(spyComparisonChecking.ts, 0, 0))
4+
5+
(...params: any[]): any;
6+
>params : Symbol(params, Decl(spyComparisonChecking.ts, 1, 5))
7+
8+
identity: string;
9+
>identity : Symbol(Spy.identity, Decl(spyComparisonChecking.ts, 1, 28))
10+
11+
and: Function;
12+
>and : Symbol(Spy.and, Decl(spyComparisonChecking.ts, 3, 21))
13+
>Function : Symbol(Function, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
14+
15+
mostRecentCall: { args: any[]; };
16+
>mostRecentCall : Symbol(Spy.mostRecentCall, Decl(spyComparisonChecking.ts, 4, 18))
17+
>args : Symbol(args, Decl(spyComparisonChecking.ts, 5, 21))
18+
19+
argsForCall: any[];
20+
>argsForCall : Symbol(Spy.argsForCall, Decl(spyComparisonChecking.ts, 5, 37))
21+
}
22+
23+
type SpyObj<T> = T & {
24+
>SpyObj : Symbol(SpyObj, Decl(spyComparisonChecking.ts, 7, 1))
25+
>T : Symbol(T, Decl(spyComparisonChecking.ts, 9, 12))
26+
>T : Symbol(T, Decl(spyComparisonChecking.ts, 9, 12))
27+
28+
[k in keyof T]: Spy;
29+
>k : Symbol(k, Decl(spyComparisonChecking.ts, 10, 5))
30+
>T : Symbol(T, Decl(spyComparisonChecking.ts, 9, 12))
31+
>Spy : Symbol(Spy, Decl(spyComparisonChecking.ts, 0, 0))
32+
}
33+
34+
declare function createSpyObj<T>(
35+
>createSpyObj : Symbol(createSpyObj, Decl(spyComparisonChecking.ts, 11, 1))
36+
>T : Symbol(T, Decl(spyComparisonChecking.ts, 13, 30))
37+
38+
name: string, names: Array<keyof T>): SpyObj<T>;
39+
>name : Symbol(name, Decl(spyComparisonChecking.ts, 13, 33))
40+
>names : Symbol(names, Decl(spyComparisonChecking.ts, 14, 17))
41+
>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
42+
>T : Symbol(T, Decl(spyComparisonChecking.ts, 13, 30))
43+
>SpyObj : Symbol(SpyObj, Decl(spyComparisonChecking.ts, 7, 1))
44+
>T : Symbol(T, Decl(spyComparisonChecking.ts, 13, 30))
45+
46+
function mock<T>(spyName: string, methodNames: Array<keyof T>): SpyObj<T> {
47+
>mock : Symbol(mock, Decl(spyComparisonChecking.ts, 14, 52))
48+
>T : Symbol(T, Decl(spyComparisonChecking.ts, 16, 14))
49+
>spyName : Symbol(spyName, Decl(spyComparisonChecking.ts, 16, 17))
50+
>methodNames : Symbol(methodNames, Decl(spyComparisonChecking.ts, 16, 33))
51+
>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
52+
>T : Symbol(T, Decl(spyComparisonChecking.ts, 16, 14))
53+
>SpyObj : Symbol(SpyObj, Decl(spyComparisonChecking.ts, 7, 1))
54+
>T : Symbol(T, Decl(spyComparisonChecking.ts, 16, 14))
55+
56+
const spyObj = createSpyObj<T>(spyName, methodNames);
57+
>spyObj : Symbol(spyObj, Decl(spyComparisonChecking.ts, 17, 9))
58+
>createSpyObj : Symbol(createSpyObj, Decl(spyComparisonChecking.ts, 11, 1))
59+
>T : Symbol(T, Decl(spyComparisonChecking.ts, 16, 14))
60+
>spyName : Symbol(spyName, Decl(spyComparisonChecking.ts, 16, 17))
61+
>methodNames : Symbol(methodNames, Decl(spyComparisonChecking.ts, 16, 33))
62+
63+
for (const methodName of methodNames) {
64+
>methodName : Symbol(methodName, Decl(spyComparisonChecking.ts, 18, 14))
65+
>methodNames : Symbol(methodNames, Decl(spyComparisonChecking.ts, 16, 33))
66+
67+
spyObj[methodName].and.returnValue(1);
68+
>spyObj[methodName].and : Symbol(Spy.and, Decl(spyComparisonChecking.ts, 3, 21))
69+
>spyObj : Symbol(spyObj, Decl(spyComparisonChecking.ts, 17, 9))
70+
>methodName : Symbol(methodName, Decl(spyComparisonChecking.ts, 18, 14))
71+
>and : Symbol(Spy.and, Decl(spyComparisonChecking.ts, 3, 21))
72+
}
73+
return spyObj;
74+
>spyObj : Symbol(spyObj, Decl(spyComparisonChecking.ts, 17, 9))
75+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
=== tests/cases/compiler/spyComparisonChecking.ts ===
2+
interface Spy {
3+
(...params: any[]): any;
4+
>params : any[]
5+
6+
identity: string;
7+
>identity : string
8+
9+
and: Function;
10+
>and : Function
11+
12+
mostRecentCall: { args: any[]; };
13+
>mostRecentCall : { args: any[]; }
14+
>args : any[]
15+
16+
argsForCall: any[];
17+
>argsForCall : any[]
18+
}
19+
20+
type SpyObj<T> = T & {
21+
>SpyObj : SpyObj<T>
22+
23+
[k in keyof T]: Spy;
24+
}
25+
26+
declare function createSpyObj<T>(
27+
>createSpyObj : <T>(name: string, names: (keyof T)[]) => SpyObj<T>
28+
29+
name: string, names: Array<keyof T>): SpyObj<T>;
30+
>name : string
31+
>names : (keyof T)[]
32+
33+
function mock<T>(spyName: string, methodNames: Array<keyof T>): SpyObj<T> {
34+
>mock : <T>(spyName: string, methodNames: (keyof T)[]) => SpyObj<T>
35+
>spyName : string
36+
>methodNames : (keyof T)[]
37+
38+
const spyObj = createSpyObj<T>(spyName, methodNames);
39+
>spyObj : SpyObj<T>
40+
>createSpyObj<T>(spyName, methodNames) : SpyObj<T>
41+
>createSpyObj : <T>(name: string, names: (keyof T)[]) => SpyObj<T>
42+
>spyName : string
43+
>methodNames : (keyof T)[]
44+
45+
for (const methodName of methodNames) {
46+
>methodName : keyof T
47+
>methodNames : (keyof T)[]
48+
49+
spyObj[methodName].and.returnValue(1);
50+
>spyObj[methodName].and.returnValue(1) : any
51+
>spyObj[methodName].and.returnValue : any
52+
>spyObj[methodName].and : Function
53+
>spyObj[methodName] : SpyObj<T>[keyof T]
54+
>spyObj : SpyObj<T>
55+
>methodName : keyof T
56+
>and : Function
57+
>returnValue : any
58+
>1 : 1
59+
}
60+
return spyObj;
61+
>spyObj : SpyObj<T>
62+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
interface Spy {
2+
(...params: any[]): any;
3+
4+
identity: string;
5+
and: Function;
6+
mostRecentCall: { args: any[]; };
7+
argsForCall: any[];
8+
}
9+
10+
type SpyObj<T> = T & {
11+
[k in keyof T]: Spy;
12+
}
13+
14+
declare function createSpyObj<T>(
15+
name: string, names: Array<keyof T>): SpyObj<T>;
16+
17+
function mock<T>(spyName: string, methodNames: Array<keyof T>): SpyObj<T> {
18+
const spyObj = createSpyObj<T>(spyName, methodNames);
19+
for (const methodName of methodNames) {
20+
spyObj[methodName].and.returnValue(1);
21+
}
22+
return spyObj;
23+
}

0 commit comments

Comments
 (0)