SpoonX/aurelia-api

Cannot use Endpoint.of as a parameter decorator

Closed this issue · 7 comments

Kukks commented

The following code results in Error: src\app.ts(18,15): error TS1239: Unable to resolve signature of parameter decorator when called as an expression. Cannot invoke an expression whose type lacks a call signature. Type 'Endpoint' has no compatible call signatures.

I'd like to resolve my endpoints in the constructor while also using autoinject in typescript. Is this possible? The example on Aurelia Hub for Resolves in TS mode seems to suggest it: http://aurelia.io/hub.html#/doc/article/aurelia/dependency-injection/latest/dependency-injection-basics/6

@autoinject
export class App {
  constructor(private authService: AuthService,
              private eventAggregator: EventAggregator,
              @Endpoint.of('protected-api')
              private privateResource: Endpoint){}
}

I have asked about autoinject before but I can't recall now what the answer was. Perhaps a search on their gitter channel will return something?

ah.. see #89

Kukks commented

Thanks @AdamWillden
Seems to me like a typing issue however?
I'll do a few tests in the morning and see what I can come up with.
I would really like to keep it purely configured through the decorator.

@Kukks Last I checked, it's not a decorator. From the docs:

import {inject} from 'aurelia-framework';
import {Endpoint} from 'aurelia-api';

@inject(Endpoint.of('api'))
export class MyClass {
  constructor(apiEndpoint) {
    this.apiEndpoint = apiEndpoint;
  }
}

Oops sorry, I just noticed this is autoinject. I've never tried that before.

autoinject does not work with resolvers.
http://aurelia.io/docs/fundamentals/dependency-injection#resolvers
they added special decorators for that, but even those don't actually work

hence it's either using @Inject or @autoinject and inject Config and not the endpoint. the rest entpoint can then be set in the constructor using the injected config.

we might better add that to the docs somewhere

after the bug in the parameter decorators provided by aurelia is fixed, we can easily add our own
see aurelia/dependency-injection#153