machty / ember-concurrency

ember-concurrency is an Ember Addon that enables you to write concise, worry-free, cancelable, restartable, asynchronous tasks.
http://ember-concurrency.com
MIT License
691 stars 155 forks source link

Typescript error: 'onState' does not exist in type 'EncapsulatedTaskDescriptor<any, any[]>' #447

Closed johanrd closed 2 years ago

johanrd commented 2 years ago

Creating a task with modifier {onState: null}:

import { task, TaskGenerator } from 'ember-concurrency';
export default class ExampleComponent extends Component<DashboardDataArgs> {
  @task({onState: null, keepLatest: false}) *exampleTask() : TaskGenerator<void> {}
}

…generates the following typescript error:

  The last overload gave the following error.
    Argument of type '{ onState: null; keepLatest: boolean; }' is not assignable to parameter of type 'EncapsulatedTaskDescriptor<any, any[]>'.
      Object literal may only specify known properties, and 'onState' does not exist in type 'EncapsulatedTaskDescriptor<any, any[]>'.

3     @task({onState: null, keepLatest: false}) * exampleTask() : TaskGenerator<void> {
               ~~~~~~~~~~~~~

  node_modules/ember-concurrency/addon/index.d.ts:873:17
    873 export function task<T extends EncapsulatedTaskDescriptor<any, any[]>>(
                        ~~~~
    The last overload is declared here.

Expected behavior from JSDoc is that onState should be nullable: https://github.com/machty/ember-concurrency/blob/9eff68cddb50ce10c58bf91f8aad90e0fc2df5d4/addon/-private/task-decorators.js#L180