Due to how the "this" keyword works in javascript Typescript creates the "_this" alias for you. This is by design, and is great when you know how it works.
Your example:
class Person {
firstname = ko.observable<string>();
lastname: ko.observable<string>();
fullname = ko.computed(
() => {
// Breakpoint here
return this.firstname() + ' ' + this.lastname();
});
}
Compiles to:
var Person = (function () {
function Person() {
var _this = this;
this.firstname = ko.observable();
this.lastname = ();
this.fullname = ko.computed(function () {
// Breakpoint here
return _this.firstname() + ' ' + _this.lastname();
});
}
return Person;
})();
This shows (as you mentioned) that "this" in your fullname computed function has been compiled to "_this". Your issue with the debugging is that Visual Studio is debugging the compiled javascript. And in javascript "this" inside the function means something else, read more about "this" in javascript here.
Typescript creates a _this reference when you use a lambda function, i.e:
class foo {
something: string = "some string";
foo1 = () => { this.something }
foo2() { this.something }
}
Compiles to:
var foo = (function () {
function foo() {
var _this = this;
this.something = "some string";
this.foo1 = function () { _this.something; };
}
foo.prototype.foo2 = function () { this.something; };
return foo;
})();
If used correctly lambda functions in typescript solves the "this" hell from javascript. In most cases you do not need to think about when to use lambdas or functions, but in some cases you do. More information about lambda functions can be found here.
The short answer for working with this is to inspect _this when working with lambdas until it is fixed.
There is an open issue for it: https://typescript.codeplex.com/workitem/1655.