cartant/ts-action

Error TS2345 on union definition

Closed this issue · 1 comments

maku commented

When I define actions in this way (using TS 2.6.2)

import { action, payload, union } from 'ts-action';

export interface Worker {
  id: string;
  name: string;
  skills?: string[];
}

export const WorkerLoad = action('[Worker] LOAD', payload<string>());
export const WorkerLoadSuccess = action('[Worker] LOAD SUCCESS', payload<Worker>());

export const WorkerSearch = action('[Worker] SEARCH', payload<string>());
export const WorkerSearchSuccess = action(
  '[Worker] SEARCH SUCCESS',
  payload<Worker[]>()
);

export const WorkerActions = union({
  WorkerLoad,
  WorkerLoadSuccess,
  WorkerSearch,
  WorkerSearchSuccess,
});

I get an error on the union definition:

Error:(19, 3) TS2345: Argument of type '{ WorkerLoad: ActionCtor<"[Worker] LOAD", new (payload: string) => { payload: string; }>; WorkerL...' is not assignable to parameter of type 'Ctor<{}>'. Object literal may only specify known properties, and 'WorkerLoad' does not exist in type 'Ctor<{}>'.

What can be the reason??

I'm unable to reproduce the problem. I copied and pasted the code from the issue, but it works for me:

https://github.com/cartant/ts-action/blob/master/source/issues-spec.ts

I'd suggest having a look to see if there are any significant differences between the tsconfig.json files, etc. However, the error seems strange; this part doesn't make much sense:

does not exist in type 'Ctor<{}>'