-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Closed
Labels
DuplicateAn existing issue was already createdAn existing issue was already createdMeta-IssueAn issue about the team, or the direction of TypeScriptAn issue about the team, or the direction of TypeScriptSuggestionAn idea for TypeScriptAn idea for TypeScript
Description
Do not discuss the details of these in this bug! Go to the appropriate linked issue to discuss them
This issue is to track all the various this proposals floating around and to distinguish them. Any comments here should be clarifying comments/questions.
Specify this as a function return value
Let type definitions specify that the type of a field (or maybe just function return values) is the same as the type that contains the property.
Example:
interface Animal {
clone(): this; // Today: clone(): Animal;
self: this;
}
interface Dog extends Animal { woof(); }
interface Cat extends Animal { meow(); }
var c: Cat;
var cc = c.clone(); // Desired: cc: Cat
cc.meow(); // Desired: OK. Today: Fails
var ccc = cc.self; // Desired: ccc: CatSpecify, as part of a function, the type of this inside the function body
Allow a syntax to specify the type of this as part of a function expression.
Example:
function fn(this: HTMLElement) {
this.focus(); // OK
}
fn(); // 'this' argument not visible externally. May or may not be errorSpecify, as part of a function type, the type of this inside a function body
(no issue yet, please leave a comment if you create one)
Allow a syntax to specify that when a function is invoked, this will be of a certain type
Example:
// http://api.jquery.com/jquery.each/
function jquery_each<T>(items: T[], callback: (this: T, index: number, value: T) { /* ... */ }
jquery_each(['foo', 'bar'], () => console.log(this.substr(1));Specify the what valid this values are during function invocation
Add type system logic to detect when a method is being invoked without a proper this context
class Foo {
bar = 5;
printBar() { console.log(this.bar); }
}
var f = new Foo();
// prints 'undefined', not '5'
window.setImmediate(f.printBar); // Flag this as an errorMetadata
Metadata
Assignees
Labels
DuplicateAn existing issue was already createdAn existing issue was already createdMeta-IssueAn issue about the team, or the direction of TypeScriptAn issue about the team, or the direction of TypeScriptSuggestionAn idea for TypeScriptAn idea for TypeScript