Description
From @thoughtentity on September 14, 2016 15:57
TypeScript this
Type Information Dosen't Surface Properly in Editor
Environment Information
- VS Code Version: 1.6.0-insiders (f31a4)
- OS Version: Windows 10 1607 (Build 14393.105)
- TypeScript Version: 2.0.2 (Release Candidate)
Problem
In TypeScript 2.0, the shape of this
for functions can be described using type annotations. However, the VS Code TypeScript editor does not properly surface this information. The this
variable in the function gets typed as any
within the function but the editor still enforces that use of this
in the function conform to the type information used to describe this
for the function. This results in the odd issue of the editor not providing any intellisense for the this
due to it being typed as any
but still expects it conform to the shape of this
described by the this
type annotation for the function.
Reproduction
The following minimum TypeScript file will reproduce the issue in VS Code.
index.ts
type ctxA = {
funB: (paramA: string) => void
}
interface TestObj {
propA: {
funA: (this: ctxA) => void
}
}
let objA: TestObj = {
propA: {
funA: function() {
// errors since funB dosen't match the signature (missing paramA) of funB in ctxA even though the editor types it as any
this.funB();
}
}
}
Expected Result
The VS Code TypeScript editor should properly surface the type information for this
in functions and not just type it as any
to provide proper intellisense.
Copied from original issue: microsoft/vscode#12032