@@ -20,12 +20,6 @@ import {
2020// @ts -expect-error Unused args
2121const noop = ( ...args : Array < any > ) => { } ;
2222
23- // @ts -expect-error Unused args
24- const isString = ( arg : string ) => { } ;
25-
26- // @ts -expect-error Unused args
27- const isNumber = ( arg : number ) => { } ;
28-
2923( ) => {
3024 const atoms = createAtomsFn (
3125 atomicWithShorthandStyles ,
@@ -134,50 +128,26 @@ const isNumber = (arg: number) => {};
134128 // @ts -expect-error - Too many responsive array options
135129 normalizeValue ( [ 'one' , 'two' , 'three' , 'four' ] ) ;
136130
137- // Valid value - default condition is provided
138- isString ( normalizeValue ( { mobile : 'hello' } ) . mobile ) ;
139-
140- // Valid value - default condition is provided
141- isString ( normalizeValue ( { mobile : 'hello' , tablet : 'world' } ) . mobile ) ;
142-
143- // @ts -expect-error - condition is potentially undefined when not default condition
144- isString ( normalizeValue ( { tablet : 'hello' } ) . tablet ) ;
145-
146- // @ts -expect-error - condition is potentially undefined when not default condition
147- isString ( normalizeValue ( { mobile : 'hello' , tablet : 'world' } ) . tablet ) ;
148-
149131 normalizeValue ( {
150132 // @ts -expect-error - Incorrect conditional keys
151133 mobille : '' ,
152134 } ) ;
153135
136+ function testGenericNormalizeValue < Key extends string | number > (
137+ value : ResponsiveValue < Key > ,
138+ ) : Key | undefined {
139+ const normalizedValue = normalizeValue ( value ) ;
140+ // Should return the Key type for each condition when normalizing
141+ return normalizedValue . mobile ;
142+ }
143+ testGenericNormalizeValue ( '' ) ;
144+
154145 // @ts -expect-error - Strings shouldn't map to objects
155146 mapValue ( alignProp , ( ) => 'baz' ) . mobile ;
156147
157148 // @ts -expect-error - Numbers shouldn't map to objects
158149 mapValue ( 3 , ( ) => 4 ) . mobile ;
159150
160- isString ( mapValue ( { mobile : 123 } , ( ) => 'abc' ) . mobile ) ;
161- isNumber ( mapValue ( { mobile : 'abc' } , ( ) => 123 ) . mobile ) ;
162-
163- // @ts -expect-error - Mobile should be potentially undefined since it wasn't provided
164- isString ( mapValue ( { tablet : 123 } , ( ) => 'abc' ) . mobile ) ;
165-
166- // @ts -expect-error - Tablet should be potentially undefined since it's not the default condition
167- isString ( mapValue ( { tablet : 123 } , ( ) => 'abc' ) . tablet ) ;
168-
169- // @ts -expect-error - Tablet should be potentially undefined since it's not the default condition
170- isString ( mapValue ( { mobile : 123 , tablet : 456 } , ( ) => 'abc' ) . tablet ) ;
171-
172- // @ts -expect-error - Mobile should be potentially undefined since it wasn't provided
173- isNumber ( mapValue ( { tablet : 'abc' } , ( ) => 123 ) . mobile ) ;
174-
175- // @ts -expect-error - Tablet should be potentially undefined since it's not the default condition
176- isNumber ( mapValue ( { tablet : 'abc' } , ( ) => 123 ) . tablet ) ;
177-
178- // @ts -expect-error - Tablet should be potentially undefined since it's not the default condition
179- isNumber ( mapValue ( { mobile : 'abc' , tablet : 'def' } , ( ) => 123 ) . tablet ) ;
180-
181151 const mapValueWithoutDefaultCondition = createMapValueFn (
182152 conditionalStylesWithoutDefaultCondition ,
183153 ) ;
@@ -188,9 +158,6 @@ const isNumber = (arg: number) => {};
188158 // @ts -expect-error - Should force conditional value as no default condition
189159 normalizeValueWithoutDefaultCondition ( 'test' ) ;
190160
191- // @ts -expect-error - Should potentially be undefined
192- isString ( normalizeValueWithoutDefaultCondition ( { active : 'yo' } ) . active ) ;
193-
194161 // @ts -expect-error - Should force conditional value as no default condition
195162 mapValueWithoutDefaultCondition ( 'test' ) ;
196163
0 commit comments