Skip to content

Commit

Permalink
Merge branch 'master' into multiple-ts-versions
Browse files Browse the repository at this point in the history
  • Loading branch information
markerikson committed Oct 16, 2019
2 parents f5c5cc9 + 8f35fd1 commit ec24833
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 10 deletions.
2 changes: 1 addition & 1 deletion 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
@@ -1,6 +1,6 @@
{
"name": "redux-starter-kit",
"version": "0.8.0",
"version": "0.8.1",
"description": "A simple set of tools to make using Redux easier",
"repository": "https://github.com/reduxjs/redux-starter-kit",
"main": "dist/redux-starter-kit.cjs.js",
Expand Down
4 changes: 2 additions & 2 deletions src/createSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export interface CreateSliceOptions<
* functions. These reducers should have existing action types used
* as the keys, and action creators will _not_ be generated.
*/
extraReducers?: CaseReducers<State, any>
extraReducers?: CaseReducers<NoInfer<State>, any>
}

type PayloadActions<Types extends keyof any = string> = Record<
Expand Down Expand Up @@ -230,7 +230,7 @@ export function createSlice<
})

const finalCaseReducers = { ...extraReducers, ...sliceCaseReducersByType }
const reducer = createReducer(initialState, finalCaseReducers)
const reducer = createReducer(initialState, finalCaseReducers as any)

return {
name,
Expand Down
12 changes: 6 additions & 6 deletions src/tsHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export type IsUnknown<T, True, False = never> = unknown extends T
: False

export type IsEmptyObj<T, True, False = never> = T extends any
? {} extends T
? IsUnknown<T, False, IsAny<T, False, True>>
? keyof T extends never
? IsUnknown<T, False, True>
: False
: never

Expand All @@ -24,11 +24,11 @@ export type IsEmptyObj<T, True, False = never> = T extends any
* * versions below 3.5 will return `{}` for unresolvable interference
* * versions above will return `unknown`
* */
export type AtLeastTS35<True, False> = IsUnknown<
export type AtLeastTS35<True, False> = [True, False][IsUnknown<
ReturnType<<T>() => T>,
True,
False
>
0,
1
>]

export type IsUnknownOrNonInferrable<T, True, False> = AtLeastTS35<
IsUnknown<T, True, False>,
Expand Down
13 changes: 13 additions & 0 deletions type-tests/files/createAction.typetest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,16 @@ function expectType<T>(p: T): T {
// typings:expect-error
expectType<string>(strLenMetaAction('test').meta)
}

/*
* regression test for https://github.com/reduxjs/redux-starter-kit/issues/214
*/
{
const action = createAction<{ input?: string }>('ACTION')
const t: string|undefined = action({input: ""}).payload.input;

// typings:expect-error
const u: number = action({input: ""}).payload.input;
// typings:expect-error
const v: number = action({input: 3}).payload.input;
}

0 comments on commit ec24833

Please sign in to comment.