Typescript to vanilla JS for injecting IHttpClient

What is this:

import { IHttpClient } from '@aurelia/fetch-client';
import { newInstanceOf } from '@aurelia/kernel';
import { ICustomElementViewModel } from 'aurelia';

export class MyService {    
    constructor(@newInstanceOf(IHttpClient) readonly http: IHttpClient) {

    }
 }   

in vanilla js?

import { inject } from 'aurelia'
import { IHttpClient } from '@aurelia/fetch-client'

@inject(IHttpClient)

export class MyService {
  constructor(http) {
    this.http = http
  }
}

I think you need the following.

import { resolve, newInstanceOf } from '@aurelia/kernel';
import { IHttpClient } from '@aurelia/fetch-client';

export class MyService {
  http = resolve(newInstanceOf(IHttpClient));
}
1 Like