Reputation: 733
I am trying to set up a VSCode environment for working with TypeScript v2.03
I start out with a simple vanilla javascript snippet I can test out in node via the integrated terminal.
function Person() {
this.name = "";
}
Person.prototype.age = 0;
let me = new Person();
I insert into the Typescript Playground website and it compiles fine with no complaints.
But when I create a new file in VSCode, the VSCode editor complains:
And if I run webpack with the ts-loader plugin I get this error:
When I run 'tsc src/test.ts' it compiles without complaints.
My questions:
Upvotes: 2
Views: 1268
Reputation: 62298
One of the main benefits to TypeScript over JavaScript is explicitly defined types. In this case a better way to configure Person
would be to define it as a class. This will restrict assignment to the known members on the type Person
.
class Person {
name: string;
age: number;
constructor(){
this.name = "";
}
}
let me = new Person();
// assignments to known members on the type Person
me.age = 21;
Upvotes: 2