viniciusdacal/redux-arc

Missing type definition for typescript

Opened this issue · 1 comments

c3s4 commented

As stated in the title I can't find any type definition to use this lib with typescript.
At the moment I added the

// @ts-ignore

comment before the import but it's only a workaround.
Any suggestion?

I'm having a look at it right now.
The most difficult part is the dynamic keys transformation, which so far is impossible with Typescript. (see https://github.com/microsoft/TypeScript/issues/12754).

We've come up with a custom .d.ts and something like this in our project:

interface ICreators {
	searchSlot: ISearchSlotCreator;
}

interface ITypes extends IReduxArcActionsTypes {
	SEARCH_SLOT: {
		REQUEST: 'REQUEST_MANAGEMENT_SEARCH_SLOT_REQUEST';
		RESPONSE: 'REQUEST_MANAGEMENT_SEARCH_SLOT_RESPONSE';
	};
	TEST_ACTION: 'REQUEST_MANAGEMENT_TEST_ACTION';
}

const { restBaseUrl } = API;

let { types, creators } = createActions<ITypes, ICreators>('requestManagement', {
	searchSlot: {
		url: `${restBaseUrl}`,
		method: 'get'
	},
	testAction: null
});

but it feels very clunky, scales badly and defeats the main purpose of this library (reduce boilerplate!)
So we are now experimenting with building a vscode extension to automatically generate type signatures for arc's createActions.
I'll let you know how it goes!