Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions tests/baselines/reference/reverseMappedThisLeak.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
reverseMappedThisLeak.ts(16,5): error TS2349: This expression is not callable.
Type 'unknown' has no call signatures.


==== reverseMappedThisLeak.ts (1 errors) ====
declare function test<T extends Record<string, unknown>>(obj:{
[K in keyof T]: () => T[K];
}): T;

const obj = test({
a() {
return 1;
},
b() {
return this.a();
// Expected: number
// Actual: T[string] (bug)
}
});

obj.b(); // should be `number`, but currently inferred as `T[string]`
~
!!! error TS2349: This expression is not callable.
!!! error TS2349: Type 'unknown' has no call signatures.
33 changes: 33 additions & 0 deletions tests/baselines/reference/reverseMappedThisLeak.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//// [tests/cases/compiler/reverseMappedThisLeak.ts] ////

//// [reverseMappedThisLeak.ts]
declare function test<T extends Record<string, unknown>>(obj:{
[K in keyof T]: () => T[K];
}): T;

const obj = test({
a() {
return 1;
},
b() {
return this.a();
// Expected: number
// Actual: T[string] (bug)
}
});

obj.b(); // should be `number`, but currently inferred as `T[string]`

//// [reverseMappedThisLeak.js]
"use strict";
var obj = test({
a: function () {
return 1;
},
b: function () {
return this.a();
// Expected: number
// Actual: T[string] (bug)
}
});
obj.b(); // should be `number`, but currently inferred as `T[string]`
45 changes: 45 additions & 0 deletions tests/baselines/reference/reverseMappedThisLeak.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//// [tests/cases/compiler/reverseMappedThisLeak.ts] ////

=== reverseMappedThisLeak.ts ===
declare function test<T extends Record<string, unknown>>(obj:{
>test : Symbol(test, Decl(reverseMappedThisLeak.ts, 0, 0))
>T : Symbol(T, Decl(reverseMappedThisLeak.ts, 0, 22))
>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --))
>obj : Symbol(obj, Decl(reverseMappedThisLeak.ts, 0, 57))

[K in keyof T]: () => T[K];
>K : Symbol(K, Decl(reverseMappedThisLeak.ts, 1, 3))
>T : Symbol(T, Decl(reverseMappedThisLeak.ts, 0, 22))
>T : Symbol(T, Decl(reverseMappedThisLeak.ts, 0, 22))
>K : Symbol(K, Decl(reverseMappedThisLeak.ts, 1, 3))

}): T;
>T : Symbol(T, Decl(reverseMappedThisLeak.ts, 0, 22))

const obj = test({
>obj : Symbol(obj, Decl(reverseMappedThisLeak.ts, 4, 5))
>test : Symbol(test, Decl(reverseMappedThisLeak.ts, 0, 0))

a() {
>a : Symbol(a, Decl(reverseMappedThisLeak.ts, 4, 18))

return 1;
},
b() {
>b : Symbol(b, Decl(reverseMappedThisLeak.ts, 7, 4))

return this.a();
>this.a : Symbol(a, Decl(reverseMappedThisLeak.ts, 4, 18))
>this : Symbol(__type, Decl(reverseMappedThisLeak.ts, 0, 61))
>a : Symbol(a, Decl(reverseMappedThisLeak.ts, 4, 18))

// Expected: number
// Actual: T[string] (bug)
}
});

obj.b(); // should be `number`, but currently inferred as `T[string]`
>obj.b : Symbol(b, Decl(reverseMappedThisLeak.ts, 7, 4))
>obj : Symbol(obj, Decl(reverseMappedThisLeak.ts, 4, 5))
>b : Symbol(b, Decl(reverseMappedThisLeak.ts, 7, 4))

60 changes: 60 additions & 0 deletions tests/baselines/reference/reverseMappedThisLeak.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//// [tests/cases/compiler/reverseMappedThisLeak.ts] ////

=== reverseMappedThisLeak.ts ===
declare function test<T extends Record<string, unknown>>(obj:{
>test : <T extends Record<string, unknown>>(obj: { [K in keyof T]: () => T[K]; }) => T
> : ^ ^^^^^^^^^ ^^ ^^ ^^^^^
>obj : { [K in keyof T]: () => T[K]; }
> : ^^^ ^^^^^^^^^^^^^^^^^^^^ ^^^

[K in keyof T]: () => T[K];
}): T;

const obj = test({
>obj : { a: number; b: T[string]; }
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>test({ a() { return 1; }, b() { return this.a(); // Expected: number // Actual: T[string] (bug) }}) : { a: number; b: T[string]; }
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>test : <T extends Record<string, unknown>>(obj: { [K in keyof T]: () => T[K]; }) => T
> : ^ ^^^^^^^^^ ^^ ^^ ^^^^^
>{ a() { return 1; }, b() { return this.a(); // Expected: number // Actual: T[string] (bug) }} : { a(): number; b(): T[string]; }
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

a() {
>a : () => number
> : ^^^^^^^^^^^^

return 1;
>1 : 1
> : ^

},
b() {
>b : () => T[string]
> : ^^^^^^^^^^^^^^^

return this.a();
>this.a() : number
> : ^^^^^^
>this.a : () => number
> : ^^^^^^^^^^^^
>this : { a: () => number; b: () => T[string]; }
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>a : () => number
> : ^^^^^^^^^^^^

// Expected: number
// Actual: T[string] (bug)
}
});

obj.b(); // should be `number`, but currently inferred as `T[string]`
>obj.b() : any
> : ^^^
>obj.b : T[string]
> : ^^^^^^^^^
>obj : { a: number; b: T[string]; }
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>b : T[string]
> : ^^^^^^^^^

18 changes: 18 additions & 0 deletions tests/cases/compiler/reverseMappedThisLeak.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// @strict: true

declare function test<T extends Record<string, unknown>>(obj:{
[K in keyof T]: () => T[K];
}): T;

const obj = test({
a() {
return 1;
},
b() {
return this.a();
// Expected: number
// Actual: T[string] (bug)
}
});

obj.b(); // should be `number`, but currently inferred as `T[string]`