1/* 2 * Copyright (c) 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16// if in real env, remvoe './sdk/' 17import { AccessibilityExtensionAbility } from './sdk/@kit.AccessibilityKit'; 18 19class EntryAbility extends AccessibilityExtensionAbility { 20 onConnect(): void { 21 let axContext = this.context; 22 let accessibilityElement = axContext.getFocusElement(); 23 accessibilityElement.then((data) => { 24 data.attributeValue<'accessibilityFocused'>('accessibilityFocused'); // error 25 }); 26 } 27 28 noErrorCase(): void { 29 let localAccessibilityElement = customFoo(); 30 localAccessibilityElement.then((data) => { 31 data.attributeValue<'accessibilityFocused'>('accessibilityFocused'); // ok 32 }); 33 34 let axContext = this.context; 35 let notAccessibilityElement = axContext.getFocusElementNotAccessibilityElement(); 36 notAccessibilityElement.then((data) => { 37 data.attributeValue<'accessibilityFocused'>('accessibilityFocused'); // ok 38 }); 39 } 40} 41interface AccessibilityElement { 42 attributeValue<T extends keyof ElementAttributeValues>( 43 attributeName: T, 44 callback: AsyncCallback<ElementAttributeValues[T]> 45 ): void; 46 attributeValue<T extends keyof ElementAttributeValues>(attributeName: T): Promise<ElementAttributeValues[T]>; 47} 48 49async function customFoo(): Promise<AccessibilityElement> { 50 return (await {}) as AccessibilityElement; 51} 52