# Class Decorator Solution no longer works

**URL:** <https://forum.codewithmosh.com/t/class-decorator-solution-no-longer-works/17361>\
**Category:** TypeScript\
**Created:** [December 31, 2022, 3:57pm UTC](https://forum.codewithmosh.com/t/class-decorator-solution-no-longer-works/17361 "2022-12-31T15:57:08Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![cheffernan087](https://avatars.discourse-cdn.com/v4/letter/c/51bf81/32.png) [@cheffernan087](https://forum.codewithmosh.com/u/cheffernan087)\
**Post date:** [December 31, 2022, 3:57pm UTC](https://forum.codewithmosh.com/t/class-decorator-solution-no-longer-works/17361/1 "2022-12-31T15:57:08Z")

</div>

The solution given for the decorators exercise in the typescript course is as follows:

```typescript
function Sauce(sauce: string) {
 return (constructor: Function) => {
 constructor.prototype.sauce = sauce;
 };
}

```

however when I ran this code, the resultant objects did not have a .sauce property. I managed to add the property by rewriting this decorator as follows:

```typescript
function Sauce(sauce: string) {
  return <T extends { new (...args: any[]): {} }>(constructor: T) => {
    return class extends constructor {
      sauce = sauce;
    };
  };
}

@Sauce("Pesto")
class Pizza {}

const pizza = new Pizza();
console.log(pizza);

```

I can see the sauce property in the output however I am still not able to do console.log(pizza.sauce) as I am getting a ts compile error telling me that the sauce property does not exist on the Pizza class. I am wondering if the syntax given in the solution is deprecated and if so does anyone know how to solve the exercise using up to date syntax in a way the the ts compiler knows about the pizza.sauce property?
