@@ -74,21 +74,36 @@ const AriaPropertyNames = [
7474 'role' ,
7575] as const ;
7676
77+ type AriaProperty = ( typeof AriaPropertyNames ) [ number ] ;
78+
7779export type AccessibleElementProperties = {
78- [ prop in ( typeof AriaPropertyNames ) [ number ] ] : string | null ;
80+ [ Prop in AriaProperty ] : string | null ;
81+ } ;
82+
83+ type AriaPropToAttrMap = {
84+ [ Prop in AriaProperty ] : Prop extends `aria${infer S } ` ? `aria-${Lowercase < S > } ` : Prop ;
85+ } ;
86+
87+ type AriaAttribute = AriaPropToAttrMap [ AriaProperty ] ;
88+
89+ type AriaAttrToPropMap = {
90+ [ Prop in AriaProperty as AriaPropToAttrMap [ Prop ] ] : Prop ;
7991} ;
8092
8193const { AriaAttrNameToPropNameMap, AriaPropNameToAttrNameMap } = /*@__PURE__ */ ( ( ) => {
82- const AriaAttrNameToPropNameMap : Record < string , string > = create ( null ) ;
83- const AriaPropNameToAttrNameMap : Record < string , string > = create ( null ) ;
94+ const AriaAttrNameToPropNameMap : AriaAttrToPropMap = create ( null ) ;
95+ const AriaPropNameToAttrNameMap : AriaPropToAttrMap = create ( null ) ;
8496
8597 // Synthetic creation of all AOM property descriptors for Custom Elements
8698 forEach . call ( AriaPropertyNames , ( propName ) => {
8799 const attrName = StringToLowerCase . call (
88100 StringReplace . call ( propName , / ^ a r i a / , ( ) => 'aria-' )
89- ) ;
90- AriaAttrNameToPropNameMap [ attrName ] = propName ;
91- AriaPropNameToAttrNameMap [ propName ] = attrName ;
101+ ) as AriaAttribute ;
102+ // These type assertions are because the map types are a 1:1 mapping of ariaX to aria-x.
103+ // TypeScript knows we have one of ariaX | ariaY and one of aria-x | aria-y, and tries to
104+ // prevent us from doing ariaX: aria-y, but we that it's safe.
105+ ( AriaAttrNameToPropNameMap [ attrName ] as AriaProperty ) = propName ;
106+ ( AriaPropNameToAttrNameMap [ propName ] as AriaAttribute ) = attrName ;
92107 } ) ;
93108
94109 return { AriaAttrNameToPropNameMap, AriaPropNameToAttrNameMap } ;
0 commit comments