ember-cli-typescript icon indicating copy to clipboard operation
ember-cli-typescript copied to clipboard

ember-concurrency-decorators typehinting.

Open pjcarly opened this issue 6 years ago • 2 comments

ember-concurrency-decorators lacks proper typehinting in the IDE.

image

The limitations are clear. Perhaps there can be a solution in the future. At the least we could document this behavior.

pjcarly avatar Mar 25 '19 14:03 pjcarly

Elaboration: this happens when you write a decorated task like this:

import Component from '@ember/component';
import { action } from '@ember-decorators/object';
import { task } from 'ember-concurrency-decorators';

export default class MyComponent extends Component {
  @task
  *fetchRecords() {
    // whatever behavior
  }

  @action
  doSomething() {
    this.fetchRecords.perform();
  }

The problem is that the type of *fetchRecords from TS' perspective is a generator function; decorators are not currently allowed to change the type of the thing they decorate. But this decorator is in fact wrapping the generator function in a Task type which has a perform method, so the type as TS sees it and the type as it behaves at runtime are different.

chriskrycho avatar Mar 25 '19 14:03 chriskrycho

Related to https://github.com/machty/ember-concurrency-decorators/issues/41

buschtoens avatar Mar 29 '19 09:03 buschtoens

This was resolved via a series of workarounds (hacks? But of a respectable variety!) in ember-concurrency. Thanks for the original reports, folks!

chriskrycho avatar Sep 28 '23 22:09 chriskrycho