import { createSelector , defaultMemoize , defaultEqualityCheck , createSelectorCreator , createStructuredSelector , ParametricSelector , OutputSelector , SelectorResultArray , Selector } from '../src' ; import microMemoize from 'micro-memoize' ; import memoizeOne from 'memoize-one' ; import { createSlice , configureStore } from '@reduxjs/toolkit' ; import { createApi , fetchBaseQuery } from '@reduxjs/toolkit/query/react' ; import { TypedUseSelectorHook , useDispatch , useSelector } from 'react-redux' ; export function expectType < T > ( t ) { return t ; } type Exact < A , B > = ( < T > ( ) => T extends A ? 1 : 0 ) extends < T > ( ) => T extends B ? 1 : 0 ? A extends B ? B extends A ? unknown : never : never : never ; export declare type IsAny < T , True , False = never > = true | false extends ( T extends never ? true : false ) ? True : False ; export declare type IsUnknown < T , True , False = never > = unknown extends T ? IsAny < T , False , True > : False ; type Equals < T , U > = IsAny < T , never , IsAny < U , never , [ T ] extends [ U ] ? ( [ U ] extends [ T ] ? any : never ) : never > > ; export function expectExactType < T > ( t ) { return < U extends Equals < T , U > > ( u ) => { } ; } interface StateA { a : number ; } interface StateAB { a : number ; b : number ; } interface StateSub { sub : { a : number ; } ; } export const testExportBasic = createSelector ( ( state ) => state . a , a => a ) ; export const testExportStructured = createSelectorCreator ( defaultMemoize , ( a , b ) => typeof a === typeof b ) ; function testSelector ( ) { type State = { foo : string ; } ; const selector = createSelector ( ( state ) => state . foo , foo => foo ) ; const res = selector . resultFunc ( 'test' ) ; selector . recomputations ( ) ; selector . resetRecomputations ( ) ; const foo = selector ( { foo : 'bar' } ) ; selector ( { foo : 'bar' } , { prop : 'value' } ) ; const num = selector ( { foo : 'bar' } ) ; createSelector ( ( state ) => state . foo , ( state ) => state . bar , ( foo , bar ) => 1 ) ; const selectorWithUnions = createSelector ( ( state , val ) => state . foo , ( state , val ) => val , ( foo , val ) => val ) ; } function testNestedSelector ( ) { type State = { foo : string ; bar : number ; baz : boolean ; } ; const selector = createSelector ( createSelector ( ( state ) => state . foo , ( state ) => state . bar , ( foo , bar ) => ( { foo , bar } ) ) , ( state ) => state . baz , ( { foo , bar } , baz ) => { const foo1 = foo ; const foo2 = foo ; const bar1 = bar ; const bar2 = bar ; const baz1 = baz ; const baz2 = baz ; } ) ; } function testSelectorAsCombiner ( ) { type SubState = { foo : string ; } ; type State = { bar : SubState ; } ; const subSelector = createSelector ( ( state ) => state . foo , foo => foo ) ; const selector = createSelector ( ( state ) => state . bar , subSelector ) ; selector ( { foo : '' } ) ; const n = selector ( { bar : { foo : '' } } ) ; const s = selector ( { bar : { foo : '' } } ) ; } type Component < P > = ( props : P ) => any ; declare function connect < S , P , R > ( selector ) ; function testConnect ( ) { connect ( createSelector ( ( state ) => state . foo , foo => ( { foo } ) ) ) ( props => { props . bar ; const foo = props . foo ; } ) ; const selector2 = createSelector ( ( state ) => state . foo , ( state , props ) => props . bar , ( foo , bar ) => ( { foo , baz : bar } ) ) ; const connected = connect ( selector2 ) ( props => { const foo = props . foo ; const bar = props . bar ; const baz = props . baz ; props . fizz ; } ) ; connected ( { bar : 42 } ) ; connected ( { bar : 42 , baz : 123 } ) ; } function testInvalidTypeInCombinator ( ) { createSelector ( ( state ) => state . foo , ( foo ) => foo ) ; createSelector ( ( state ) => state . foo , ( state ) => state . bar , ( state ) => state . baz , ( foo , bar , baz , fizz ) => { } ) ; createSelector ( ( state ) => state . testString , ( state ) => state . testNumber , ( state ) => state . testBoolean , ( state ) => state . testString , ( state ) => state . testString , ( state ) => state . testString , ( state ) => state . testString , ( state ) => state . testNumber , ( state ) => state . testStringArray , ( foo1 , foo2 , foo3 , foo4 , foo5 , foo6 , foo7 , foo8 , foo9 ) => { return { foo1 , foo2 , foo3 , foo4 , foo5 , foo6 , foo7 , foo8 , foo9 } ; } ) ; createSelector ( [ ( state ) => state . testString , ( state ) => state . testNumber , ( state ) => state . testBoolean , ( state ) => state . testString , ( state ) => state . testString , ( state ) => state . testString , ( state ) => state . testString , ( state ) => state . testNumber , ( state ) => state . testStringArray ] , ( foo1 , foo2 , foo3 , foo4 , foo5 , foo6 , foo7 , foo8 , foo9 ) => { return { foo1 , foo2 , foo3 , foo4 , foo5 , foo6 , foo7 , foo8 , foo9 } ; } ) ; } function testParametricSelector ( ) { type State = { foo : string ; } ; type Props = { bar : number ; } ; const selector1 = createSelector ( ( state ) => state . testString , ( state ) => state . testNumber , ( state ) => state . testBoolean , ( state ) => state . testString , ( state ) => state . testString , ( state ) => state . testString , ( state ) => state . testString , ( state ) => state . testString , ( state ) => state . testStringArray , ( foo1 , foo2 , foo3 , foo4 , foo5 , foo6 , foo7 , foo8 , foo9 ) => { return { foo1 , foo2 , foo3 , foo4 , foo5 , foo6 , foo7 , foo8 , foo9 } ; } ) ; const res1 = selector1 ( { testString : 'a' , testNumber : 42 , testBoolean : true , testStringArray : [ 'b' , 'c' ] } ) ; const selector = createSelector ( ( state ) => state . foo , ( state , props ) => props . bar , ( foo , bar ) => ( { foo , bar } ) ) ; selector ( { foo : 'fizz' } ) ; selector ( { foo : 'fizz' } , { bar : 'baz' } ) ; const ret = selector ( { foo : 'fizz' } , { bar : 42 } ) ; const foo = ret . foo ; const bar = ret . bar ; const selector2 = createSelector ( ( state ) => state . foo , ( state ) => state . foo , ( state ) => state . foo , ( state ) => state . foo , ( state ) => state . foo , ( state , props ) => props . bar , ( foo1 , foo2 , foo3 , foo4 , foo5 , bar ) => ( { foo1 , foo2 , foo3 , foo4 , foo5 , bar } ) ) ; selector2 ( { foo : 'fizz' } , { bar : 42 } ) ; const selector3 = createSelector ( ( s ) => s . foo , ( s , x ) => x , ( s , y ) => y , ( v , x ) => { return x + v ; } ) ; selector3 ( { foo : 'fizz' } , 42 ) ; const selector4 = createSelector ( ( s , val ) => s . foo , ( s , val ) => val , ( foo , val ) => { return val ; } ) ; selector4 ( { foo : 'fizz' } , 42 ) ; } function testArrayArgument ( ) { const selector = createSelector ( [ ( state ) => state . foo , ( state ) => state . foo , ( state , props ) => props . bar ] , ( foo1 , foo2 , bar ) => ( { foo1 , foo2 , bar } ) ) ; const ret = selector ( { foo : 'fizz' } , { bar : 42 } ) ; const foo1 = ret . foo1 ; const foo2 = ret . foo2 ; const bar = ret . bar ; createSelector ( [ ( state ) => state . foo ] ) ; createSelector ( [ ( state ) => state . foo , ( state ) => state . foo ] , ( foo , bar ) => { } ) ; createSelector ( [ ( state ) => state . foo , ( state ) => state . foo , ( state ) => state . foo , ( state ) => state . foo , ( state ) => state . foo , ( state ) => state . foo , ( state ) => state . foo , ( state ) => state . foo , ( state ) => state . foo , ( state ) => state . foo ] , ( foo1 , foo2 , foo3 , foo4 , foo5 , foo6 , foo7 , foo8 , foo9 , foo10 ) => { } ) ; createSelector ( [ ( state ) => state . foo , ( state ) => state . foo , ( state ) => state . foo , ( state ) => state . foo , ( state ) => state . foo , ( state ) => state . foo , ( state ) => state . foo , ( state ) => state . foo , ( state ) => state . foo , ( state ) => state . foo ] , ( foo1 , foo2 , foo3 , foo4 , foo5 , foo6 , foo7 , foo8 , foo9 , foo10 ) => { } ) ; createSelector ( [ ( state ) => state . foo , state => state . foo , state => state . foo , state => state . foo , state => state . foo , state => state . foo , state => state . foo , state => state . foo , 1 ] , ( foo1 , foo2 , foo3 , foo4 , foo5 , foo6 , foo7 , foo8 , foo9 ) => { } ) ; const selector2 = createSelector ( [ ( state ) => state . foo , ( state ) => state . foo , ( state ) => state . foo , ( state ) => state . foo , ( state ) => state . foo , ( state ) => state . foo , ( state ) => state . foo , ( state ) => state . foo , ( state ) => state . foo ] , ( foo1 , foo2 , foo3 , foo4 , foo5 , foo6 , foo7 , foo8 , foo9 ) => { return { foo1 , foo2 , foo3 , foo4 , foo5 , foo6 , foo7 , foo8 , foo9 } ; } ) ; { const ret = selector2 ( { foo : 'fizz' } ) ; const foo1 = ret . foo1 ; const foo2 = ret . foo2 ; const foo3 = ret . foo3 ; const foo4 = ret . foo4 ; const foo5 = ret . foo5 ; const foo6 = ret . foo6 ; const foo7 = ret . foo7 ; const foo8 = ret . foo8 ; const foo9 = ret . foo9 ; ret . foo10 ; } selector2 ( { foo : 'fizz' } , { bar : 42 } ) ; const parametric = createSelector ( [ ( state , props ) => props . bar , ( state ) => state . foo , ( state ) => state . foo , ( state ) => state . foo , ( state ) => state . foo , ( state ) => state . foo , ( state ) => state . foo , ( state ) => state . foo , ( state ) => state . foo ] , ( bar , foo1 , foo2 , foo3 , foo4 , foo5 , foo6 , foo7 , foo8 ) => { return { foo1 , foo2 , foo3 , foo4 , foo5 , foo6 , foo7 , foo8 , bar } ; } ) ; const correctlyTypedArraySelector = createSelector ( [ ( state ) => state . testString , ( state ) => state . testNumber , ( state ) => state . testBoolean , ( state ) => state . testString , ( state ) => state . testString , ( state ) => state . testString , ( state ) => state . testString , ( state ) => state . testString , ( state ) => state . testStringArray ] , ( foo1 , foo2 , foo3 , foo4 , foo5 , foo6 , foo7 , foo8 , foo9 ) => { return { foo1 , foo2 , foo3 , foo4 , foo5 , foo6 , foo7 , foo8 , foo9 } ; } ) ; parametric ( { foo : 'fizz' } ) ; { const ret = parametric ( { foo : 'fizz' } , { bar : 42 } ) ; const foo1 = ret . foo1 ; const foo2 = ret . foo2 ; const foo3 = ret . foo3 ; const foo4 = ret . foo4 ; const foo5 = ret . foo5 ; const foo6 = ret . foo6 ; const foo7 = ret . foo7 ; const foo8 = ret . foo8 ; const bar = ret . bar ; ret . foo9 ; } } function testDefaultMemoize ( ) { const func = ( a ) => + a ; const memoized = defaultMemoize ( func ) ; const ret0 = memoized ( '42' ) ; const ret1 = memoized ( '42' ) ; const memoized2 = defaultMemoize ( ( str , arr ) : { str : string ; arr : string [ ] ; } => ( { str , arr } ) , < T > ( a , b ) => { return `${ a }` === `${ b }` ; } ) ; const ret2 = memoized2 ( '' , [ '1' , '2' ] ) ; const str = ret2 . str ; const arr = ret2 . arr ; } function testCreateSelectorCreator ( ) { const defaultCreateSelector = createSelectorCreator ( defaultMemoize ) ; const selector = defaultCreateSelector ( ( state ) => state . foo , foo => foo ) ; const value = selector ( { foo : 'fizz' } ) ; selector ( { foo : 'fizz' } , { bar : 42 } ) ; selector . clearCache ( ) ; const parametric = defaultCreateSelector ( ( state ) => state . foo , ( state , props ) => props . bar , ( foo , bar ) => ( { foo , bar } ) ) ; parametric ( { foo : 'fizz' } ) ; const ret = parametric ( { foo : 'fizz' } , { bar : 42 } ) ; const foo = ret . foo ; const bar = ret . bar ; createSelectorCreator ( defaultMemoize , 1 ) ; createSelectorCreator ( defaultMemoize , < T > ( a , b ) => { return `${ a }` === `${ b }` ; } ) ; } function testCreateStructuredSelector ( ) { const oneParamSelector = createStructuredSelector ( { foo : ( state ) => state . a , bar : ( state ) => state . b } ) ; const threeParamSelector = createStructuredSelector ( { foo : ( state , c , d ) => state . a , bar : ( state , c , d ) => state . b } ) ; const selector = createStructuredSelector < { foo : string ; } , { foo : string ; bar : number ; } > ( { foo : state => state . foo , bar : state => + state . foo } ) ; const res1 = selector ( { foo : '42' } ) ; const foo = res1 . foo ; const bar = res1 . bar ; selector ( { bar : '42' } ) ; selector ( { foo : '42' } , { bar : 42 } ) ; createStructuredSelector < { foo : string ; } , { bar : number ; } > ( { bar : ( state ) => 1 } ) ; createStructuredSelector < { foo : string ; } , { bar : number ; } > ( { bar : state => state . foo } ) ; createStructuredSelector < { foo : string ; } , { bar : number ; } > ( { baz : state => state . foo } ) ; type State = { foo : string ; } ; const FooSelector = ( state , a , b ) => state . foo ; const BarSelector = ( state , a , b ) => + state . foo ; const selector2 = createStructuredSelector ( { foo : FooSelector , bar : BarSelector } ) ; const selectorGenerics = createStructuredSelector < { foo : typeof FooSelector ; bar : typeof BarSelector ; } > ( { foo : state => state . foo , bar : state => + state . foo } ) ; type ExpectedResult = { foo : string ; bar : number ; } ; const resOneParam = oneParamSelector ( { a : 1 , b : 2 } ) ; const resThreeParams = threeParamSelector ( { a : 1 , b : 2 } , 99 , 'blah' ) ; const res2 = selector ( { foo : '42' } ) ; const res3 = selector2 ( { foo : '42' } , 99 , 'test' ) ; const resGenerics = selectorGenerics ( { foo : '42' } , 99 , 'test' ) ; selector2 ( { bar : '42' } ) ; selectorGenerics ( { bar : '42' } ) ; } function testDynamicArrayArgument ( ) { interface Elem { val1 : string ; val2 : string ; } const data = [ { val1 : 'a' , val2 : 'aa' } , { val1 : 'b' , val2 : 'bb' } ] ; createSelector ( data . map ( obj => ( ) => obj . val1 ) , ( ... vals ) => vals . join ( ',' ) ) ; createSelector ( data . map ( obj => ( ) => obj . val1 ) , vals => vals . join ( ',' ) ) ; createSelector ( data . map ( obj => ( ) => obj . val1 ) , ( ... vals ) => 0 ) ; createSelector ( data . map ( obj => ( ) => obj . val1 ) , ( ... vals ) => 0 ) ; const s = createSelector ( data . map ( obj => ( state , fld ) => obj [ fld ] ) , ( ... vals ) => vals . join ( ',' ) ) ; s ( { a : 42 } , 'val1' ) ; s ( { a : 42 } , 'val2' ) ; s ( { a : 42 } , 'val3' ) ; } function testStructuredSelectorTypeParams ( ) { type GlobalState = { foo : string ; bar : number ; } ; const selectFoo = ( state ) => state . foo ; const selectBar = ( state ) => state . bar ; createStructuredSelector < GlobalState > ( { foo : selectFoo } ) ; createStructuredSelector < GlobalState > ( { foo : selectFoo , bar : selectBar } ) ; createStructuredSelector < GlobalState , Omit < GlobalState , 'bar' > > ( { foo : selectFoo } ) ; } function multiArgMemoize < F extends ( ... args : any [ ] ) => any > ( func , a , b , equalityCheck = defaultEqualityCheck ) { return ( ) => { } ; } import { isEqual , groupBy } from 'lodash' ; import { GetStateFromSelectors } from '../src/types' ; { interface Transaction { transactionId : string ; } const toId = ( transaction ) => transaction . transactionId ; const transactionsIds = ( transactions ) => transactions . map ( toId ) ; const collectionsEqual = ( ts1 , ts2 ) => isEqual ( transactionsIds ( ts1 ) , transactionsIds ( ts2 ) ) ; const createTransactionsSelector = createSelectorCreator ( defaultMemoize , collectionsEqual ) ; const createMultiMemoizeArgSelector = createSelectorCreator ( multiArgMemoize , 42 , 'abcd' , defaultEqualityCheck ) ; const select = createMultiMemoizeArgSelector ( ( state ) => state . foo , foo => foo + '!' ) ; select . clearCache ( ) ; const createMultiMemoizeArgSelector2 = createSelectorCreator ( multiArgMemoize , 42 , defaultEqualityCheck ) ; const groupTransactionsByLabel = defaultMemoize ( ( transactions ) => groupBy ( transactions , item => item . transactionId ) , collectionsEqual ) ; } function issue445 ( ) { interface TestState { someNumber : number | null ; someString : string | null ; } interface Object1 { str : string ; } interface Object2 { num : number ; } const getNumber = ( state ) => state . someNumber ; const getString = ( state ) => state . someString ; function generateObject1 ( str ) { return { str } ; } function generateObject2 ( num ) { return { num } ; } function generateComplexObject ( num , subObject , subObject2 ) { return true ; } const getObject1 = createSelector ( [ getString ] , generateObject1 ) ; const getObject2 = createSelector ( [ getNumber ] , generateObject2 ) ; const getComplexObjectTest1 = createSelector ( [ getObject1 ] , generateComplexObject ) ; const getComplexObjectTest2 = createSelector ( [ getNumber , getObject1 ] , generateComplexObject ) ; const getComplexObjectTest3 = createSelector ( [ getNumber , getObject1 , getObject2 ] , generateComplexObject ) ; const getComplexObjectTest4 = createSelector ( [ getObject1 , getNumber , getObject2 ] , generateComplexObject ) ; const getVerboseObject1 = createSelector ( [ getString ] , str => generateObject1 ( str ) ) ; const getVerboseObject2 = createSelector ( [ getNumber ] , num => generateObject2 ( num ) ) ; const getVerboseComplexObjectTest1 = createSelector ( [ getObject1 ] , obj1 => generateComplexObject ( obj1 ) ) ; const getVerboseComplexObjectTest2 = createSelector ( [ getNumber , getObject1 ] , ( num , obj1 ) => generateComplexObject ( num , obj1 ) ) ; const getVerboseComplexObjectTest3 = createSelector ( [ getNumber , getObject1 , getObject2 ] , ( num , obj1 , obj2 ) => generateComplexObject ( num , obj1 , obj2 ) ) ; const getVerboseComplexObjectTest4 = createSelector ( [ getObject1 , getNumber , getObject2 ] , ( num , obj1 , obj2 ) => generateComplexObject ( num , obj1 , obj2 ) ) ; } function issue492 ( ) { const fooPropSelector = ( _ , ownProps ) => ownProps . foo ; const fooBarPropsSelector = ( _ , ownProps ) => [ ownProps . foo , ownProps . bar ] ; const combinedSelector = createSelector ( fooPropSelector , fooBarPropsSelector , ( foo , fooBar ) => fooBar ) ; } function customMemoizationOptionTypes ( ) { const customMemoize = ( f , a , b , c ) => { return f ; } ; const customSelectorCreatorCustomMemoizeWorking = createSelectorCreator ( customMemoize , 'a' , 42 , true ) ; const customSelectorCreatorCustomMemoizeMissingArg = createSelectorCreator ( customMemoize , 'a' , true ) ; } function createSelectorConfigOptions ( ) { const defaultMemoizeAcceptsFirstArgDirectly = createSelector ( ( state ) => state . a , ( state ) => state . b , ( a , b ) => a + b , { memoizeOptions : ( a , b ) => a === b } ) ; const defaultMemoizeAcceptsFirstArgAsObject = createSelector ( ( state ) => state . a , ( state ) => state . b , ( a , b ) => a + b , { memoizeOptions : { equalityCheck : ( a , b ) => a === b } } ) ; const defaultMemoizeAcceptsArgsAsArray = createSelector ( ( state ) => state . a , ( state ) => state . b , ( a , b ) => a + b , { memoizeOptions : [ ( a , b ) => a === b ] } ) ; const customSelectorCreatorMicroMemoize = createSelectorCreator ( microMemoize , { maxSize : 42 } ) ; customSelectorCreatorMicroMemoize ( ( state ) => state . a , ( state ) => state . b , ( a , b ) => a + b , { memoizeOptions : [ { maxSize : 42 } ] } ) ; const customSelectorCreatorMemoizeOne = createSelectorCreator ( memoizeOne ) ; customSelectorCreatorMemoizeOne ( ( state ) => state . a , ( state ) => state . b , ( a , b ) => a + b , { memoizeOptions : ( a , b ) => a === b } ) ; } const withLotsOfInputSelectors = createSelector ( ( _state ) => 1 , ( _state ) => 2 , ( _state ) => 3 , ( _state ) => 4 , ( _state ) => 5 , ( _state ) => 6 , ( _state ) => 7 , ( _state ) => 8 , ( _state ) => 9 , ( _state ) => 10 , ( _state ) => 11 , ( _state ) => 12 , ( _state ) => 13 , ( _state ) => 14 , ( _state ) => 15 , ( _state ) => 16 , ( _state ) => 17 , ( _state ) => 18 , ( _state ) => 19 , ( _state ) => 20 , ( _state ) => 21 , ( _state ) => 22 , ( _state ) => 23 , ( _state ) => 24 , ( _state ) => 25 , ( _state ) => 26 , ( _state ) => 27 , ( _state ) => 28 , ( ... args ) => args . length ) ; type SelectorArray29 = [ ( _state : StateA ) => 1 , ( _state : StateA ) => 2 , ( _state : StateA ) => 3 , ( _state : StateA ) => 4 , ( _state : StateA ) => 5 , ( _state : StateA ) => 6 , ( _state : StateA ) => 7 , ( _state : StateA ) => 8 , ( _state : StateA ) => 9 , ( _state : StateA ) => 10 , ( _state : StateA ) => 11 , ( _state : StateA ) => 12 , ( _state : StateA ) => 13 , ( _state : StateA ) => 14 , ( _state : StateA ) => 15 , ( _state : StateA ) => 16 , ( _state : StateA ) => 17 , ( _state : StateA ) => 18 , ( _state : StateA ) => 19 , ( _state : StateA ) => 20 , ( _state : StateA ) => 21 , ( _state : StateA ) => 22 , ( _state : StateA ) => 23 , ( _state : StateA ) => 24 , ( _state : StateA ) => 25 , ( _state : StateA ) => 26 , ( _state : StateA ) => 27 , ( _state : StateA ) => 28 , ( _state : StateA ) => 29 ] ; type Results = SelectorResultArray < SelectorArray29 > ; type State = GetStateFromSelectors < SelectorArray29 > ; { const input1 = ( state ) => 1 ; const input2 = ( state ) => 2 ; const selector = createSelector ( input1 , input2 , ( ... args ) => 0 ) ; selector ( 'foo' ) ; selector ( 5 ) ; } { const selector = createSelector ( ( state ) => 1 , ( state ) => 2 , ( ... args ) => 0 ) ; selector ( { foo : '' , bar : '' } ) ; selector ( { foo : '' } ) ; selector ( { bar : '' } ) ; } { const selector = createSelector ( ( state ) => 1 , ( state ) => 2 , ( ... args ) => 0 ) ; selector ( { foo : '' , bar : '' } ) ; selector ( { foo : '' } ) ; selector ( { bar : '' } ) ; } function testInputSelectorWithUndefinedReturn ( ) { type Input = { field : number | undefined ; } ; type Output = string ; type SelectorType = ( input : Input ) => Output ; const input = ( { field } ) => field ; const result = ( out ) : Output => 'test' ; const selector = createSelector ( ( { field } ) => field , args => 'test' ) ; const selector2 = createSelector ( ( { field } ) => field , args => 'test' , { memoizeOptions : { maxSize : 42 } } ) ; const selector3 = createSelector ( input , result ) ; const selector4 = createSelector ( input , result , { memoizeOptions : { maxSize : 42 } } ) ; } function deepNesting ( ) { type State = { foo : string ; } ; const readOne = ( state ) => state . foo ; const selector0 = createSelector ( readOne , one => one ) ; const selector1 = createSelector ( selector0 , s => s ) ; const selector2 = createSelector ( selector1 , s => s ) ; const selector3 = createSelector ( selector2 , s => s ) ; const selector4 = createSelector ( selector3 , s => s ) ; const selector5 = createSelector ( selector4 , s => s ) ; const selector6 = createSelector ( selector5 , s => s ) ; const selector7 = createSelector ( selector6 , s => s ) ; const selector8 = createSelector ( selector7 , s => s ) ; const selector9 = createSelector ( selector8 , s => s ) ; const selector10 = createSelector ( selector9 , s => s ) ; const selector11 = createSelector ( selector10 , s => s ) ; const selector12 = createSelector ( selector11 , s => s ) ; const selector13 = createSelector ( selector12 , s => s ) ; const selector14 = createSelector ( selector13 , s => s ) ; const selector15 = createSelector ( selector14 , s => s ) ; const selector16 = createSelector ( selector15 , s => s ) ; const selector17 = createSelector ( selector16 , s => s ) ; const selector18 = createSelector ( selector17 , s => s ) ; const selector19 = createSelector ( selector18 , s => s ) ; const selector20 = createSelector ( selector19 , s => s ) ; const selector21 = createSelector ( selector20 , s => s ) ; const selector22 = createSelector ( selector21 , s => s ) ; const selector23 = createSelector ( selector22 , s => s ) ; const selector24 = createSelector ( selector23 , s => s ) ; const selector25 = createSelector ( selector24 , s => s ) ; const selector26 = createSelector ( selector25 , s => s ) ; const selector27 = createSelector ( selector26 , s => s ) ; const selector28 = createSelector ( selector27 , s => s ) ; const selector29 = createSelector ( selector28 , s => s ) ; } function issue540 ( ) { const input1 = ( _ , { testNumber } , c , d ) => testNumber ; const input2 = ( _ , { testString } , c ) => testString ; const input3 = ( _ , { testBoolean } , c , d ) => testBoolean ; const input4 = ( _ , { testString2 } ) => testString2 ; const testSelector = createSelector ( input1 , input2 , input3 , input4 , ( testNumber , testString , testBoolean ) => testNumber + testString ) ; const state = { a : 42 } ; const test = testSelector ( state , { testNumber : 1 , testString : '10' , testBoolean : true , testString2 : 'blah' } , 42 , 'blah' ) ; const selectProp1 = createSelector ( [ ( state ) => state , ( state , props ) => props ] , ( state , { prop1 } ) => [ state , prop1 ] ) ; const selectProp2 = createSelector ( [ selectProp1 , ( state , props ) => props ] , ( state , { prop2 } ) => [ state , prop2 ] ) ; selectProp1 ( { a : 42 } , { prop1 : 1 } ) ; selectProp2 ( { a : 42 } , { prop2 : 2 } ) ; } function issue548 ( ) { interface State { value : Record < string , any > | null ; loading : boolean ; } interface Props { currency : string ; } const isLoading = createSelector ( ( state ) => state , ( _ , props ) => props . currency , ( { loading } , currency ) => loading ) ; const mapData = createStructuredSelector ( { isLoading , test2 : ( state ) => 42 } ) ; const result = mapData ( { value : null , loading : false } , { currency : 'EUR' } ) ; } function issue550 ( ) { const some = createSelector ( ( a ) => a , ( _a , b ) => b , ( a , b ) => a + b ) ; const test = some ( 1 , 2 ) ; } function rtkIssue1750 ( ) { const slice = createSlice ( { name : 'test' , initialState : 0 , reducers : { } } ) ; interface Pokemon { name : string ; } const pokemonApi = createApi ( { reducerPath : 'pokemonApi' , baseQuery : fetchBaseQuery ( { baseUrl : 'https://pokeapi.co/api/v2/' } ) , endpoints : builder => ( { getPokemonByName : builder . query < Pokemon , string > ( { query : name => `pokemon/${ name }` } ) } ) } ) ; const store = configureStore ( { reducer : { test : slice . reducer , [ pokemonApi . reducerPath ] : pokemonApi . reducer } , middleware : getDefaultMiddleware => getDefaultMiddleware ( ) . concat ( pokemonApi . middleware ) } ) ; type RootState = ReturnType < typeof store . getState > ; const selectTest = createSelector ( ( state ) => state . test , test => test ) ; const useAppSelector = useSelector ; const testItem = selectTest ( store . getState ( ) ) ; function App ( ) { const test = useAppSelector ( selectTest ) ; return null ; } } function handleNestedIncompatTypes ( ) { const input1a = ( _ , param ) => param . b ; const input1b = ( _ , param ) => param . b ; const testSelector1 = createSelector ( input1a , input1b , ( ) => ( { } ) ) ; testSelector1 ( { a : 42 } , { b : 99 } ) ; const input2a = ( _ , param ) => param . b . c ; const input2b = ( _ , param ) => param . b . c ; const testSelector2 = createSelector ( input2a , input2b , ( c1 , c2 ) => { } ) ; testSelector2 ( { a : 42 } , { b : { c : 99 } } ) ; } function issue554a ( ) { interface State { foo : string ; bar : number ; } const initialState = { foo : 'This is Foo' , bar : 1 } ; const getFoo = ( state ) => { return state . foo ; } ; getFoo ( initialState ) ; const getBar = ( state ) => { return state . bar ; } ; getBar ( initialState ) ; const simple = createSelector ( getFoo , getBar , ( foo , bar ) => { return `${ foo } => ${ bar }` ; } ) ; simple ( initialState ) ; const firstInput = ( _ , first ) => first ; const secondInput = ( _ , _first , second ) => second ; const complexOne = createSelector ( getFoo , getBar , firstInput , ( foo , bar , first ) => { return `${ foo } => ${ bar } || ${ first }` ; } ) ; complexOne ( initialState , 'first' ) ; const complexTwo = createSelector ( getFoo , getBar , firstInput , secondInput , ( foo , bar , first , second ) => { return `${ foo } => ${ bar } || ${ first } and ${ second }` ; } ) ; complexTwo ( initialState , 'first' , 'second' ) ; } function issue554b ( ) { interface State { counter1 : number ; counter2 : number ; } const selectTest = createSelector ( ( state , numberA ? ) => numberA , ( state ) => state . counter2 , ( numberA , counter2 ) => ( numberA ? numberA + counter2 : counter2 ) ) ; type selectTestParams = Parameters < typeof selectTest > ; const p1 = [ { counter1 : 1 , counter2 : 2 } , 42 ] ; expectExactType < [ State , number ? ] > ( p1 ) ; const result = selectTest ( { counter1 : 1 , counter2 : 2 } , 42 ) ; } function issue554c ( ) { interface State { counter1 : number ; counter2 : number ; } const selectTest = createSelector ( ( state , numberA ? ) => numberA , ( state ) => state . counter2 , ( numberA , counter2 ) => ( numberA ? numberA + counter2 : counter2 ) ) ; const value = selectTest ( { counter1 : 0 , counter2 : 0 } , 'what?' ) ; const selectTest2 = createSelector ( ( state , numberA ) => numberA , ( state ) => state . counter2 , ( numberA , counter2 ) => ( numberA ? numberA + counter2 : counter2 ) ) ; const value2 = selectTest2 ( { counter1 : 0 , counter2 : 0 } , 'what?' ) ; } function issue555 ( ) { type IReduxState = { ui : { x : string ; y : string ; } ; } ; const someSelector1 = createSelector ( ( state , param ) => param !== undefined ? state . ui [ param ] : null , ( a ) => a ) ; const someSelector2 = createSelector ( ( state , param ? ) => param !== undefined ? state . ui [ param ] : null , ( a ) => a ) ; const someSelector3 = createSelector ( ( state , param ) => param !== null ? state . ui [ param ] : null , ( a ) => a ) ; const state = { ui : { x : '1' , y : '2' } } ; const selectorResult1 = someSelector1 ( state , undefined ) ; const selectorResult2 = someSelector2 ( state , undefined ) ; const selectorResult3 = someSelector3 ( state , null ) ; }