Providing typing for "this" in a function

Topics: General, Language Specification
Jan 15, 2013 at 12:31 PM

Hey guys,

Does the TypeScript team have any plans to provide a way to describe and enforce the type of "this" in a function. For example, in the future would we be able to write something like this:

func(str: string) : void, this : number

In this example, there is annotation that "this" will be typed as a number. Perhaps, functions typed this way can only be called by using .call or .apply, with the first parameter set to the appropriate type.

Jan 15, 2013 at 1:41 PM

Just came across the answer: