Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Declare "EmptyObject" interface to wrap $CombinedState #4031

Merged
merged 1 commit into from
Mar 8, 2021

Conversation

JacobLey
Copy link

@JacobLey JacobLey commented Mar 8, 2021


name: Declare EmptyObject interface to wrap $CombinedState
about: Adding interface for $CombinedState appeases latest version of Typescript, allows exporting result of combineReducers

PR Type

Does this PR add a new feature, or fix a bug?

Fix a bug with lastest version of Typescript

Why should this PR be included?

No changes to exports are included, but the internal change from type->interface allows Typescript to correctly reference/export usage of $CombinedState

Checklist

New Features

What new capabilities does this PR add?

None, just maintains support of typescript with latest 4.2.x releases

What docs changes are needed to explain this?

None

Bug Fixes

What is the current behavior, and the steps to reproduce the issue?

Upgrade to typescript v2.4.2

Create a file example.ts with the following content:

import { combineReducers, $CombinedState } from 'redux';

export default combineReducers({})

make sure declarations: true is in your tsconfig.json

Typescript will emit an error on:
Default export of the module has or is using private name '$CombinedState'.

Also see #4029 for minimal reproducible issue

What is the expected behavior?

No error should be emitted

How does this PR fix the problem?

combineReducers<S>() returns a type of Reducer<CombinedState<S>>, and the CombinedState<S> is the type in question in this PR

https://www.typescriptlang.org/docs/handbook/advanced-types.html#interfaces-vs-type-aliases
Digging a bit into how Typescript works, but basically a type is an alias. So any usage of a type that internally uses $CombinedState means the resulting declaration must also use $CombinedState. Since that value is not exported, Typescript fails.

Using an interface however does not need direct access to $CombinedState, so the exporting of combineReducers will magically succeed.

@timdorr
Copy link
Member

timdorr commented Mar 8, 2021

It looks like the issue is more that we're saying readonly [$CombinedState]?: undefined extends just [$CombinedState]: undefined. So, just a signature mismatch that's no longer allowed.

In any case, this both resolves it and keeps it from being a likely issue in the future. Thanks!

@timdorr timdorr merged commit c3cbe2e into reduxjs:4.x Mar 8, 2021
webMasterMrBin pushed a commit to webMasterMrBin/redux that referenced this pull request Aug 21, 2021
webMasterMrBin pushed a commit to webMasterMrBin/redux that referenced this pull request Aug 21, 2021
webMasterMrBin pushed a commit to webMasterMrBin/redux that referenced this pull request Aug 21, 2021
webMasterMrBin pushed a commit to webMasterMrBin/redux that referenced this pull request Aug 21, 2021
webMasterMrBin pushed a commit to webMasterMrBin/redux that referenced this pull request Aug 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants