Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ export type PreloadedState<S> = Required<S> extends {
}
: never
: {
[K in keyof S]: S[K] extends object ? PreloadedState<S[K]> : S[K]
[K in keyof S]: S[K] extends (string | number | boolean | symbol)
? S[K]
: PreloadedState<S[K]>
}

/* reducers */
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"rollup-plugin-replace": "^2.2.0",
"rollup-plugin-terser": "^5.1.1",
"rxjs": "^6.5.2",
"typescript": "^3.5.3",
"typescript": "^3.9.6",
"typings-tester": "^0.3.2"
},
"npmName": "redux",
Expand Down
25 changes: 18 additions & 7 deletions test/typescript/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@ import {
} from 'redux'
import 'symbol-observable'

type BrandedString = string & { _brand: 'type' }
const brandedString = 'a string' as BrandedString

type State = {
a: 'a'
b: {
c: 'c'
d: 'd'
}
c: BrandedString
}

interface DerivedAction extends Action {
Expand All @@ -30,7 +34,8 @@ const reducer: Reducer<State> = (
b: {
c: 'c',
d: 'd'
}
},
c: brandedString
},
action: Action
): State => {
Expand All @@ -43,7 +48,8 @@ const reducerWithAction: Reducer<State, DerivedAction> = (
b: {
c: 'c',
d: 'd'
}
},
c: brandedString
},
action: DerivedAction
): State => {
Expand All @@ -58,17 +64,20 @@ const store: Store<State> = createStore(reducer)

const storeWithPreloadedState: Store<State> = createStore(reducer, {
a: 'a',
b: { c: 'c', d: 'd' }
b: { c: 'c', d: 'd' },
c: brandedString
})
// typings:expect-error
const storeWithBadPreloadedState: Store<State> = createStore(reducer, {
b: { c: 'c' }
b: { c: 'c' },
c: brandedString
})

const storeWithActionReducer = createStore(reducerWithAction)
const storeWithActionReducerAndPreloadedState = createStore(reducerWithAction, {
a: 'a',
b: { c: 'c', d: 'd' }
b: { c: 'c', d: 'd' },
c: brandedString
})
funcWithStore(storeWithActionReducer)
funcWithStore(storeWithActionReducerAndPreloadedState)
Expand All @@ -77,7 +86,8 @@ funcWithStore(storeWithActionReducerAndPreloadedState)
const storeWithActionReducerAndBadPreloadedState = createStore(
reducerWithAction,
{
b: { c: 'c' }
b: { c: 'c' },
c: brandedString
}
)

Expand All @@ -89,7 +99,8 @@ const storeWithPreloadedStateAndEnhancer: Store<State> = createStore(
reducer,
{
a: 'a',
b: { c: 'c', d: 'd' }
b: { c: 'c', d: 'd' },
c: brandedString
},
enhancer
)
Expand Down