Typescript class decorator doesn't work the way it is expected

257 Views Asked by At

I have the example code below:

function BaseEntity(ctr: Function) {
    ctr.prototype.id = Math.random();
    ctr.prototype.created = new Date();
  }

@BaseEntity
class User {
  constructor(public name: string) {}
}

let user = new User("Sarah");
console.log(user.id);

When I run this i got

Property 'id' does not exist on type 'User'.

The experimentalDecorators property is enabled.

What is the problem?

0

There are 0 best solutions below