Closed hsz closed 5 years ago
During some tests, I have removed from node_modules/typesafe-actions/dist/create-reducer.d.ts
following line:
declare type HandleActionChainApi<TState, TInputAction extends Action, TRootAction extends Action> = <TActionCreator extends (...args: any[]) => TInputAction, THandledAction extends ReturnType<TActionCreator>, TOutputAction extends Exclude<TInputAction, THandledAction>>(singleOrMultipleCreatorsAndTypes: TActionCreator | TActionCreator[], reducer: (state: TState, action: THandledAction) => TState) => [TOutputAction] extends [never] ? Reducer<TState, TRootAction> & {
handlers: Record<TRootAction['type'], (state: TState, action: TRootAction) => TState>;
} : Reducer<TState, TRootAction> & {
handlers: Record<Exclude<TRootAction, TOutputAction>['type'], (state: TState, action: TRootAction) => TState>;
handleAction: HandleActionChainApi<TState, TOutputAction, TRootAction>;
- handleType: HandleTypeChainApi<TState, TOutputAction, TRootAction>;
};
Project is building correctly and blazing fast.
So it looks like new handleType
feature causes this memory leak again.
I checked the issue and there is no memory leak, createReducer
cannot be used without at least one handler declared.
So the possible improvement here could be to update type definitions to disallow an incorrect usage.
Here is the solution, will deploy in a few minutes:
This check will be useful for sure, but when providing at least one action handler, the problem is still valid. I've updated issue repository.
Actually, I noticed another issue, but it is only present in watch mode, normal tsc call works fine. I guess your original issue is related to the watch mode issue.
Not sure what to do with that it kinda seems like a compiler bug.
Yeah, when running CRA app in development mode with npm start
, it runs watch mode as well.
In general, app is built properly and available in browser, but tsc stucks on
Files successfully emitted, waiting for typecheck results...
and fails at the end because of memory overflow.
The thing is that typesafe-actions@4.4.2
works fine with this setup.
@hsz ok I found and fixed the issue. It was infinite lazy evaluation lookup in recursive type when any type was used.
I'll release fix soon.
any type of what? I'm asking, because in my real-world app I'm trying to cover everything with types and this issue also is present.
@hsz thanks for cooperation helping me to fix that issue. New version was released so you can try now npm i typesafe-actions@next
to confirm it is fixed on your side.
When you was using createReducer without passing explicit type arg any is the default action type
Now I realized it should probably be unknown instead of any
So I've upgraded library to 5.0.0-1
and provided RootAction
globally as described in docs, but createReducer
doesn't recognize types in handleAction
callbacks:
Repo upgraded.
You did a small mistake:
interface Types {
RootAction: RootAction;
}
You're right - now there is no error, but it still stucks on typecheck.
Yeah, something else will take a look later
@hsz Ok now should be working fine. Please try typesafe-actions@5.0.0-2
I have to disable mix-and-match API so it's either handleType or handleAction but not both in a single reducer
All right, I can confirm that with 5.0.0-2
the issue with CRA and tsc watch is resolved. Thanks!
Description
With the @next release (
5.0.0-0
), create-react-app hangs on waiting for the typecheck results in a specific case, when an imported map of reducers is passed tocombineReducers
:content.ts
Above code causes a memory leak and crash at the end. When modified to:
it still hangs which is a bit interesting - so we still have
export default createReducer
inside unused/not importedcontent.ts
file. When this file is removed, everything builds correctly.Steps to Reproduce
Repository contains isolated issue with minimal setup: https://github.com/hsz/typesafe-actions-issue
Run
It'll stuck on
and emit at the end:
Expected behavior
tsc doesn't hang
Suggested solution(s)
Project Dependencies