# Aurelia v1 - issue with decorators and TypeScript 5

**URL:** <https://discourse.aurelia.io/t/aurelia-v1-issue-with-decorators-and-typescript-5/5163>\
**Category:** Framework Knowledge\
**Created:** [May 11, 2023, 4:49pm UTC](https://discourse.aurelia.io/t/aurelia-v1-issue-with-decorators-and-typescript-5/5163 "2023-05-11T16:49:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![nenadvicentic](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/nenadvicentic/32/1191_2.png) [@nenadvicentic](https://discourse.aurelia.io/u/nenadvicentic)\
**Post date:** [May 11, 2023, 4:49pm UTC](https://discourse.aurelia.io/t/aurelia-v1-issue-with-decorators-and-typescript-5/5163/1 "2023-05-11T16:49:23Z")

</div>

When using TypeScript 5.x (which is now default in Visual Studio Code) Aurelia v1 decorators are throwing a compilation error.

For this piece of code:

```ts
export class Step1 {
    constructor(@newInstance(ValidationService) validationService: ValidationService) {
    }
}

```

```shell
Unable to resolve signature of parameter decorator when called as an expression.
  Argument of type 'typeof Step1' is not assignable to parameter of type 'DependencyCtor<ValidationService, ValidationService, [_ignoreHidden?: boolean | undefined]> & { inject?: (boolean | undefined)[] | undefined; }'.
    Type 'typeof Step1' is not assignable to type 'DependencyCtor<ValidationService, ValidationService, [_ignoreHidden?: boolean | undefined]>'.
      Types of construct signatures are incompatible.
        Type 'new (validationService: ValidationService) => Step1' is not assignable to type 'new (_ignoreHidden?: boolean | undefined) => ValidationService'.ts(1239)

```

Adding a workaround `as any` works for the simplest case, where `ValidationService` constructor does not accept any parameters:

```ts
@newInstance(ValidationService as any)

```

However, for the cases where I need to pass constructor parameters to `ValidationService` like:

```ts
@newInstance(ValidationService, true)

```

there is no workaround, as far as I can tell.

How are TypeScript definitions generated for Aurealia v1 (since it’s built with ES, not TS)? Is it possible to update or regenerate TS definitions, to fix this issue for TypeScript 5?

---

<div class="post-metadata">

**Author:** ![m-gallesio](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/m-gallesio/32/1288_2.png) [@m-gallesio](https://discourse.aurelia.io/u/m-gallesio)\
**Post date:** [May 12, 2023, 7:15am UTC](https://discourse.aurelia.io/t/aurelia-v1-issue-with-decorators-and-typescript-5/5163/2 "2023-05-12T07:15:02Z")

</div>

We have been using Aurelia 1 with TypeScript 5.X with no issues so far.  
I think Aurelia 1 needs its decorators to work in the classic (then experimental, now legacy) way, by specifying the following TypeScript compiler options:

```json
{
  "compilerOptions": {
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true
  }
}

```

---

<div class="post-metadata">

**Author:** ![nenadvicentic](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/nenadvicentic/32/1191_2.png) [@nenadvicentic](https://discourse.aurelia.io/u/nenadvicentic)\
**Post date:** [May 12, 2023, 8:57am UTC](https://discourse.aurelia.io/t/aurelia-v1-issue-with-decorators-and-typescript-5/5163/3 "2023-05-12T08:57:03Z")

</div>

@m-gallesio No, unfortunately configuration is not the issue. Experimental decorators have been turned on in this project since years. If I compile it with TypeScript 4.9.5 everything works fine.

I suspect that you don’t have the issue because you don’t use decorators in constructors. I also have no issue putting `@autoinject` on top of the class.

The error states that issue is that return type of `@newInstance` is a parent class (`Step1`) and not actual type I want to instantiate (`ValidationService`). I suspect that TypeScript 5 is more precise with decorator return types than earlier versions, due to work that also went in ES decorators, so it catches the type error that has been there all the time.

---

<div class="post-metadata">

**Author:** ![m-gallesio](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/m-gallesio/32/1288_2.png) [@m-gallesio](https://discourse.aurelia.io/u/m-gallesio)\
**Post date:** [May 12, 2023, 12:24pm UTC](https://discourse.aurelia.io/t/aurelia-v1-issue-with-decorators-and-typescript-5/5163/4 "2023-05-12T12:24:15Z")

</div>

Indeed, we mostly use `bindable` and `autoinject`.  
This (turning off type checking for the decorator function) _might_ work as a workaround:

```typescript
@(newInstance as any)(MyService, parameters) myService: MyService

```
