TypeScript Version: 2.9.1-insiders.20180525
Search Terms:
function type this
Code
interface PasswordReset {
working: string;
}
type Validator = (
this: PasswordReset,
rule: any,
value: any,
callback: (error?: Error) => void
) => string;
const someFunc: Validator = function(rule, value, callback) {
console.log(this.working === true);
return 'OK';
};
interface OtherInterface {
working: string;
}
function thisWorks(this: OtherInterface, name: string) {
console.log(this.wr === true); //works as expected
}
Expected behavior:
There should be contextual awareness of what interface 'this' refers to.
Actual behavior:
'this' is shown as type 'any' in someFunc func
Playground Link:
Link
Related Issues: