From 78c33255e85eaa29d60af5cfa48b2f6bc8cdf207 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Sat, 10 Aug 2024 10:44:30 -0500 Subject: [PATCH] Revert type tests in `createSelector.withTypes.test-d.ts` --- type-tests/createSelector.withTypes.test-d.ts | 47 ++++++++++--------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/type-tests/createSelector.withTypes.test-d.ts b/type-tests/createSelector.withTypes.test-d.ts index e59959082..68eed370a 100644 --- a/type-tests/createSelector.withTypes.test-d.ts +++ b/type-tests/createSelector.withTypes.test-d.ts @@ -60,19 +60,20 @@ describe('type tests', () => { // result function are NOT correctly inferred when // input selectors are provided as separate inline arguments. createAppSelector( - [ - state => { - expectTypeOf(state).toEqualTypeOf(rootState) + state => { + expectTypeOf(state).toEqualTypeOf(rootState) - return state.todos - } - ], + return state.todos + }, todos => { // Known limitation: Parameter types are not inferred in this scenario - expectTypeOf(todos).not.toBeAny() + expectTypeOf(todos).toBeAny() - expectTypeOf(todos).toEqualTypeOf() + expectTypeOf(todos).not.toEqualTypeOf() + // @ts-expect-error A typed `createSelector` currently only infers + // the parameter types of the result function when + // input selectors are provided as a single array. return todos.map(({ id }) => id) } ) @@ -82,32 +83,34 @@ describe('type tests', () => { // Checking to see if the type of state is correct when multiple // input selectors are provided as separate inline arguments. createAppSelector( - [ - state => { - expectTypeOf(state).toEqualTypeOf(rootState) + state => { + expectTypeOf(state).toEqualTypeOf(rootState) - return state.todos - }, - state => { - expectTypeOf(state).toEqualTypeOf(rootState) + return state.todos + }, + state => { + expectTypeOf(state).toEqualTypeOf(rootState) - return state.alerts - } - ], + return state.alerts + }, (todos, alerts) => { // Known limitation: Parameter types are not inferred in this scenario - expectTypeOf(todos).not.toBeAny() + expectTypeOf(todos).toBeAny() - expectTypeOf(alerts).not.toBeAny() + expectTypeOf(alerts).toBeAny() + // @ts-expect-error A typed `createSelector` currently only infers + // the parameter types of the result function when + // input selectors are provided as a single array. return todos.map(({ id }) => id) } ) }) test('can annotate parameter types of the result function to workaround type inference issue', () => { - createAppSelector([state => state.todos], todos => - todos.map(({ id }) => id) + createAppSelector( + state => state.todos, + (todos: Todo[]) => todos.map(({ id }) => id) ) }) })