Description
TypeScript Version: 2.9.2 (also tried typescript@next 3.1.0-dev.20180725)
VSCode version: 1.25.1
Search Terms: this argument jsdoc vscode
I am trying to add TypeScript typechecking using VSCode's intellisense + JSDoc annotation in my AngularJS project. I should be able to explicitly define a type of this
keyword in a function by providing explicit this
parameter in as described here.
Code
component.d.ts
import 'angular'
declare interface IComponentCtrl {
$onChanges?(onChangesObj: ng.IOnChangesObject): void;
}
declare interface IComponent extends ng.IComponentOptions {
controller(this: IComponentCtrl, ...args: any[]): void;
}
component.js
// @ts-check
/** @type {import('./component').IComponent} */
export const component = {
controller() {
/** @type {import('./component').IComponentCtrl} */
const vm = this
vm.$onChanges = (onChangesObj) => {} // onChangesObj: angular.IOnChangesObject
this.$onChanges = (onChangesObj) => {} // onChangesObj: any
}
}
Expected behavior:
When I define controller's type of this
explicitly as interface with $onChanges method with argument of specific type, I should get type hints for the argument in the defined method.
Actual behavior:
The argument in this.$onChanges
method has type any
and the type checking works only if I assign this
to another variable and explicitly add type annotation to the newly created variable.