Skip to content

Commit

Permalink
Merge pull request #4078 from phryneas/fix-preloadedState
Browse files Browse the repository at this point in the history
  • Loading branch information
markerikson authored Oct 28, 2021
2 parents cf2f265 + 9ab0a70 commit ef5e57e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export type PreloadedState<S> = Required<S> extends EmptyObject
? {
[K in keyof S1]?: S1[K] extends object ? PreloadedState<S1[K]> : S1[K]
}
: never
: S
: {
[K in keyof S]: S[K] extends string | number | boolean | symbol
? S[K]
Expand Down
23 changes: 23 additions & 0 deletions test/typescript/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
StoreEnhancerStoreCreator,
Unsubscribe,
Observer,
PreloadedState,
CombinedState,
} from 'redux'
// @ts-ignore
import $$observable from '../src/utils/symbol-observable'
Expand Down Expand Up @@ -151,3 +153,24 @@ const observer: Observer<State> = {
}
const unsubscribeFromObservable = observable.subscribe(observer).unsubscribe
unsubscribeFromObservable()

// some type tests for PreloadedState
const ANY: any = {}
const notNever: PreloadedState<{ key: unknown }>['key'] = ANY as unknown
// typings:expect-error
const isNever: PreloadedState<{ key: never }>['key'] = ANY as unknown
const is5: 5 = ANY as PreloadedState<{ key: 5 }>['key']
// typings:expect-error
const isNot5: 5 = ANY as PreloadedState<{ key: 6 }>['key']
const isNumber: number = ANY as PreloadedState<{ key: number }>['key']
const isString: string = ANY as PreloadedState<{ key: string }>['key']
const isNested: { nested: string } = ANY as PreloadedState<{
key: { nested: string }
}>['key']
const isNestedOptional: { nested?: string } = ANY as PreloadedState<{
key: CombinedState<{ nested: string }>
}>['key']
// typings:expect-error
const isNestedReallyOptional: { nested: string } = ANY as PreloadedState<{
key: CombinedState<{ nested: string }>
}>['key']

0 comments on commit ef5e57e

Please sign in to comment.