It appears that the question has been posed before, but my search yielded no results. The issue at hand seems rather straightforward. TypeScript integrates well with object literal notation, however, when methods are defined within, it struggles to handle the this
context inside those functions. It appears that this
is assigned the type any
, resulting in a lack of auto-completion.
var foo = {
log(str) {
console.log(str);
},
print(str) {
this. /* No autocompletion */
}
};
foo. /* Normal autocompletion */
One would naturally expect that auto-completion should function properly within a method just like it does when utilizing the foo
variable. While it's possible to first declare a class and then instantiate the object, why is it necessary to do so without declaring an intermediate class
or interface
? In this simple case, it feels unnecessary like boilerplate code.