Skip to content

Consider removing DefaultRootState type #1879

Closed

Description

React-Redux v8 currently has a DefaultRootState type defined:

react-redux/src/types.ts

Lines 13 to 23 in 4d38402

/**
* This interface can be augmented by users to add default types for the root state when
* using `react-redux`.
* Use module augmentation to append your own type definition in a your_custom_type.d.ts file.
* https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation
*/
// tslint:disable-next-line:no-empty-interface
export interface DefaultRootState {}
export type AnyIfEmpty<T extends object> = keyof T extends never ? any : T
export type RootStateOrAny = AnyIfEmpty<DefaultRootState>

This was copy-pasted directly from the @types/react-redux types in DefinitelyTyped, which have had that for a while.

We Redux maintainers were not involved in that type being added originally, and specifically think it's a bad practice:

Or to say it bluntly: If at that point in time, we as Redux maintainers would have known about what was going on in DefinitelyTyped, we would have prevented DefaultRootState from ever being added. Unfortunately, at that point we were not aware.

It is a global enhancement of the state, no matter if the reducer was actually added to your store.

At one point in time, some library will go ahead and pollute that interface and suddenly every project using that library will have an extra property in their Redux store - without any reducer for it being present.

There is a good reason we don't recommend doing this anywhere in the docs.

Given that, I'd like to propose removing it from the v8 typings before this gets released.

I'm assuming we'd want to replace that with unknown instead.

I did a couple code searches, and I see maybe 1000-1500 usages in the wild:

So that's not zero, but it isn't a thing that would completely break the ecosystem in the upgrade process.

Lenz also said that this is a pattern that could get replicated in userspace if desired, although I'm not sure what the details are on that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions