There are a few differences but the most important in my opinion is that when you add a class method, TypeScript will transpile it to be a so-called prototype method, which is kind of shared for all object instances. On the other hand, adding the method to the object in the constructor will add it only to that object instance, possibly overwriting any prototype method with the same name.
Each scenario might have its use-cases, but in my experience, most of the times you should prefer the prototype methods, so in TypeScript, class methods. Also it fits more into TypeScript's OO world.
You can read more about prototype members versus object members for example here.
Another difference is that the Class 2 example might not even be valid TypeScript code (depending on version I guess), because basically you're dynamically adding the method to the instance, and not statically declaring it in the class. Even if you can make it valid TypeScript (e.g. using hacks like casting to any
), I'm pretty sure you will loose for example editor intellisense for the method printData
.