Skip to content

Commit eb7b4c2

Browse files
fix #2727:
class member function type is assigned to a normal function type
1 parent 382aabe commit eb7b4c2

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

src/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1063,7 +1063,7 @@ export class Signature {
10631063
} else {
10641064
// check `this` type (invariant)
10651065
if (thisThisType) {
1066-
if (targetThisType != targetThisType) return false;
1066+
if (targetThisType == null) return false;
10671067
} else if (targetThisType) {
10681068
return false;
10691069
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"asc_flags": [],
3+
"stderr": [
4+
"TS2322: Type '(this: class-member-function-as-parameter/C, i32) => i32' is not assignable to type '(i32) => i32'."
5+
]
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class C {
2+
aa: i32 = 1;
3+
callback(a: i32): i32 {
4+
return this.aa + a + 3;
5+
}
6+
}
7+
8+
function expectCallback(c1: (arg0: i32) => i32): i32 {
9+
return c1(4);
10+
}
11+
12+
export function fut(): i32 {
13+
const c1 = new C();
14+
return expectCallback(c1.callback);
15+
}

0 commit comments

Comments
 (0)