question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Combine reducers with intersected type of unions causes tsc to crash

See original GitHub issue

TypeScript Version: 3.4.0-dev.201xxxxx Typescript version: 3.4.5

Search Terms: Redux combine reducers memory crash heap allocation

Code


// es6 import statements for actions and reducers

type FormActions = SignUpFormActionTypes &
  LoginFormActionTypes &
  ContactUsFormActionTypes &
  ForgotPasswordFormActionTypes &
  ResetPasswordFormActionTypes &
  CreateBusinessFormActionTypes &
  BusinessDetailsFormActionTypes &
  DealFormActionsTypes &
  InstantDealFormActionsTypes &
  JobListingFormActionTypes &
  OnlineLocationFormActionTypes &
  PhysicalLocationFormActionTypes;

export default combineReducers<FormsState, FormActions>({
  signUpForm: SignUpFormReducer,
  loginForm: LoginFormReducer,
  contactUsForm: ContactUsFormReducer,
  forgotPasswordForm: ForgotPasswordFormReducer,
  resetPasswordForm: ResetPasswordFormReducer,
  createBusinessForm: CreateBusinessFormReducer,
  businessDetailsForm: BusinessDetailsFormReducer,
  dealForm: DealFormReducer,
  instantDealForm: InstantDealFormReducer,
  jobListingForm: JobListingFormReducer,
  onlineLocationForm: OnlineLocationFormReducer,
  physicalLocationForm: PhysicalLocationFormReducer,
});

For example, an action type looks like this:


export type LoginFormActionTypes =
  | SubmitLoginAction
  | LoginSuccessAction
  | LoginFailedAction;

And each of those actions are plain javascript classes that implement from Action<> in the redux library

Expected behavior: Should run tsc without issues

Actual behavior: npx tsc

<— Last few GCs —>

[59352:0000023E65B36200] 42665 ms: Mark-sweep 1391.2 (1425.2) -> 1390.9 (1425.7) MB, 966.8 / 0.0 ms (average mu = 0.081, current mu = 0.003) allocation failure scavenge might not succeed [59352:0000023E65B36200] 43644 ms: Mark-sweep 1391.8 (1425.7) -> 1391.4 (1426.2) MB, 952.3 / 0.0 ms (average mu = 0.055, current mu = 0.027) allocation failure scavenge might not succeed

<— JS stacktrace —>

==== JS stack trace =========================================

0: ExitFrame [pc: 000002A7DB3DC5C1]
1: StubFrame [pc: 000002A7DB3A26EE]

Security context: 0x030e7eb1e6e1 <JSObject> 2: slice [0000030E7EB06D09](this=0x03034251dc11 <JSArray[12]>,0) 3: /* anonymous /(aka / anonymous */) [000003034251DCC9] [D:\Workspace\business-portal\node_modules\typescript\lib\tsc.js:~33214] [pc=000002A7DC4AFFD1](this=0x0054b7c826f1 <undefined>,t=0x0074346aaf91 <Type map = 0000002A182ED9C9>) 4: argu…

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory 1: 00007FF79DD9ECF5 2: 00007FF79DD781A6 3: 00007FF79DD78BB0 4: 00007FF79E009AAE 5: 00007FF79E0099DF 6: 00007FF79E547724 7: 00007FF79E53DE87 8: 00007FF79E53C3FC 9: 00007FF79E545377 10: 00007FF79E5453F6 11: 00007FF79E0E84B7 12: 00007FF79E18019A 13: 000002A7DB3DC5C1

When I replace the action type of combineReducers to combineReducers<FormsState, any>, tsc runs and webpack compiles with linting.

These are my compiler options in tsconfig

"compilerOptions: {
    "outDir": "dist",
    "sourceMap": true,
    "allowSyntheticDefaultImports": true,
    "declaration": false,
    "noFallthroughCasesInSwitch": true,
    "importHelpers": true,
    "noEmitHelpers": true,
    "noImplicitAny": true,
    "skipLibCheck": true,
    "strictNullChecks": true,
    "noImplicitThis": true,
    "alwaysStrict": true,
    "isolatedModules": true,
    "allowJs": true,
    "checkJs": true,
    "module": "es2015",
    "noImplicitReturns": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "strict": true,
    "pretty": true,
    "removeComments": true,
    "target": "es5",
    "jsx": "react"
}

When I remove two or more declared action(s) that are part of the intersected FormActions type, tsc compiles again.

Related Issues:

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
ajafffcommented, May 7, 2019

How can one reproduce this without knowing the types of your Actions and Reducers?

Also please fix the formatting of the opening post. It’s a pain to read.

0reactions
amcaseycommented, Nov 17, 2022

I have no recollection of why this ceased to be Needs Investigation or why I grabbed it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeScript discriminated union and intersection types
An intersection type combines multiple types into one. Conditional intersection via union type. It is possible to achieve conditional ...
Read more >
Typescript Combine Types - Officina Creativa
Typescript Combine TypesTo combine types, you use the & operator as follows: The ... Combine reducers with intersected type of unions causes tsc...
Read more >
typescript-cheatsheet - GitHub Pages
The cheatsheet contains references to types, classes, decorators, ... In TypeScript, an intersection type is simply a mix (more commonly referred to as...
Read more >
Typescript Combine Types - Sporting Club Pegli 2
TypeScript Union Types Previous Next Union types are used when a value can be more ... Combine reducers with intersected type of unions...
Read more >
combine reducers for react hooks and context with type-safe
For the mainReducer function I can fix the code to work by making the action of all my reducer take a discriminated unions...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found