Loading...
Loading...
This skill should be used when the user asks to "design ArkUI API", "add component property", "create Modifier method", "review ArkUI API", "deprecate API", "write JSDOC for ArkUI", or mentions OpenHarmony API design standards. Provides comprehensive guidance for ArkUI component API design following OpenHarmony coding guidelines, including static/dynamic interface synchronization, SDK compilation, and verification.
npx skill4agent add openharmonyinsight/openharmony-skills arkui-api-designreferences/OpenHarmony-Application-Typescript-JavaScript-coding-guide.md.static.d.etsOpenHarmony/interface/sdk-js/api/arkui/component/<component>.static.d.ets@Builder@static@since [version]@since 26 static// File: text.static.d.ets
/**
* Provides a text component.
*
* @syscap SystemCapability.ArkUI.ArkUI.Full
* @since 7 static
*/
declare class Text {
/**
* Text content.
*
* @type { string | Resource }
* @syscap SystemCapability.ArkUI.ArkUI.Full
* @since 7 static
* @stagemodelonly
*/
content: string | Resource;
/**
* Creates a text component.
*
* @param content - Text content.
* @syscap SystemCapability.ArkUI.ArkUI.Full
* @since 7 static
* @stagemodelonly
*/
constructor(content: string | Resource);
}.d.tsOpenHarmony/interface/sdk-js/api/@internal/component/ets/<component>.d.tsdynamic@since [version]@since 26 dynamic// File: text.d.ts (in @internal/component/ets/)
/**
* Text Attribute interface.
*
* @syscap SystemCapability.ArkUI.ArkUI.Full
* @since 7 dynamic
*/
declare class TextAttribute extends CommonMethod<TextAttribute> {
/**
* Sets the text content.
*
* @param value - Text content to display.
* @syscap SystemCapability.ArkUI.ArkUI.Full
* @since 7 dynamic
* @stagemodelonly
*/
content(value: string | Resource): TextAttribute;
}*Modifier.d.tsarkui/AttributeModifier| Scenario | Static API | Dynamic API |
|---|---|---|
| Add property | Add to class/interface | Add to Attribute class |
| Deprecate property | Mark as | Mark as |
| Change signature | Update class definition | Update Attribute method |
| File location | | |
| Version tag | | |
| Return type | Use | Use concrete Attribute type |
ResourceStrResourceStr// ❌ WRONG: Using ResourceStr for API 12 (existing property)
content(value: ResourceStr): TextAttribute // API 12 - DO NOT MODIFY
// ✅ CORRECT: Using string | Resource for API 12 (maintaining backward compatibility)
content(value: string | Resource): TextAttribute // API 12 - KEEP AS IS
// ✅ CORRECT: Using ResourceStr for NEW API 13 (new property)
fontSize(value: number | string | Length | ResourceStr): TextAttribute // API 13 - NEW PROPERTY
// Benefits:
// - Maintains backward compatibility for existing APIs
// - Allows simplification for new APIs
// - Clear version boundary at API 13// Theme-related - YES, support Resource (API 12: keep original type)
fontSize(value: number | string | Length | Resource): TextAttribute
// API 12 and earlier: Maintain string | Resource for compatibility
// Theme-related - YES, support Resource (API 13+: use ResourceStr)
fontSize(value: number | string | Length | ResourceStr): TextAttribute
// API 13 and later: Simplified type
// Usage examples (API 12 - old API, keep string | Resource):
Text().fontSize(16) // number
Text().fontSize('16vp') // string
Text().fontSize($r('app.float.font_size_large')) // Resource
// Usage examples (API 13+ - new API, use ResourceStr):
Text().fontSize(16) // number
Text().fontSize('16vp') // string
Text().fontSize($r('app.float.font_size_large')) // Resource (ResourceStr covers this too)// State flags - NO, these are runtime-only
stateEffect(value: boolean): ButtonAttribute
enabled(value: boolean): CommonMethod
// Event callbacks - NO, these are runtime-only
onClick(callback: () => void): CommonMethodResourceStrstring | Resourceundefinednull/**
* Sets font size of text.
* @param value Font size value. If undefined, restores to default size (16fp).
* If null, removes the font size setting and uses inherited value.
* @throws {Error} Throws error if value is negative.
* @since 10
*/
fontSize(value: number | string | Length | Resource | undefined | null): TextAttribute;undefinednullvp// Good: Default to vp
width(value: number | string): ButtonAttribute // 100 means 100vp
// Good: Explicit vp
width(value: Length): ButtonAttribute // Length.type defaults to vp
// Avoid: Require px without good reason
width(value: number): ButtonAttribute // 100px - avoid unless necessary/**
* Sets border radius of component.
* @param value Border radius value. Valid range: 0-1000vp.
* Values exceeding 1000vp will be clamped to 1000vp.
* Negative values are treated as 0.
* @unit vp
* @since 10
*/
borderRadius(value: number | string | Length): CommonMethod;width()height()padding()margin()opacity()visibility()borderRadius()onClick()onTouch()interface/interface/sdk-js/api/arkui/component/*.static.d.etsinterface/sdk-js/api/@internal/component/ets/*.d.tsinterface/sdk-js/api/arkui/*Modifier.d.tsace_engine/1. Design API
├─ Define property types and constraints
├─ Document undefined/null behavior
└─ Check cross-component impact
2. Create Static API (.static.d.ets)
├─ Add property to component class
├─ Write complete JSDOC
└─ Include @since, @syscap tags
3. Create Dynamic API (@internal/component/ets/*.d.ts)
├─ Add method to Attribute class
├─ Match signature with static API
└─ Synchronize JSDOC documentation
4. Verify Type Safety
├─ Check TypeScript compilation
├─ Validate type definitions
└─ Ensure signature consistency
5. Build SDK
├─ Run SDK build command
└─ Monitor compilation errors
6. Verify SDK Output
├─ Check generated API files
├─ Verify new APIs are exported
└─ Test API availabilitycomponent/*.static.d.ets@internal/component/ets/*.d.ts.static.d.ets@internal/component/ets/*.d.ts@since X static@since X dynamicthis@deprecated@deprecated# From OpenHarmony root directory
./build.sh --export-para PYCACHE_ENABLE:true --product-name ohos-sdk --ccache--export-para PYCACHE_ENABLE:true--product-name ohos-sdk--ccacheout/ohos-sdk/
├── interfaces/
│ └── sdk-js/
│ └── api/
│ └── arkui/
│ ├── component/ # Generated .static.d.ets files
│ │ ├── button.static.d.ets
│ │ ├── text.static.d.ets
│ │ └── ...
│ ├── ButtonModifier.d.ts # Generated .d.ts files
│ ├── TextModifier.d.ts
│ └── ...# Check if .static.d.ets file contains your changes
grep -n "yourNewProperty" out/ohos-sdk/interfaces/sdk-js/api/arkui/component/<yourcomponent>.static.d.ets# Check if @internal/component/ets/*.d.ts file contains your changes
grep -n "yourNewMethod" out/ohos-sdk/interfaces/sdk-js/api/@internal/component/ets/<your_component>.d.ts.static.d.ets@internal/component/ets/*.d.ts@since X static@since X dynamic| Issue | Symptom | Solution |
|---|---|---|
| Type mismatch | Build fails with type error | Check signatures match between static/dynamic APIs |
| Missing import | Cannot find type | Add proper import statements |
| JSDOC error | Documentation warning | Fix JSDOC syntax, ensure all tags are valid |
| Sync error | API exists in one file only | Add to both static and dynamic files |
button.static.d.ets/**
* Provides a button component.
*
* @syscap SystemCapability.ArkUI.ArkUI.Full
* @since 7
*/
declare class Button {
/**
* Button type.
*
* @type { ButtonType }
* @syscap SystemCapability.ArkUI.ArkUI.Full
* @since 7
*/
type: ButtonType;
/**
* Button state.
*
* @type { ButtonState }
* @syscap SystemCapability.ArkUI.ArkUI.Full
* @since 7
*/
stateEffect: boolean;
/**
* Creates a button component.
*
* @param label - Button label text.
* @param options - Button options.
* @syscap SystemCapability.ArkUI.ArkUI.Full
* @since 7
*/
constructor(label: string | Resource, options?: ButtonOptions);
}button.d.ts@internal/component/ets//**
* Button Attribute class.
*
* @syscap SystemCapability.ArkUI.ArkUI.Full
* @since 7 dynamic
*/
declare class ButtonAttribute extends CommonMethod<ButtonAttribute> {
/**
* Sets the button type.
*
* @param value - Button type to set.
* @syscap SystemCapability.ArkUI.ArkUI.Full
* @since 7 dynamic
*/
type(value: ButtonType): ButtonAttribute;
/**
* Enables or disables state effect.
*
* @param value - Whether to enable state effect. Default is true.
* If undefined, enables state effect.
* @syscap SystemCapability.ArkUI.ArkUI.Full
* @since 7 dynamic
*/
stateEffect(value: boolean): ButtonAttribute;
}iconSize// File: button.static.d.ets
declare class Button {
// Existing properties...
/**
* Icon size.
*
* @type { number | string }
* @unit vp
* @default 24vp
* @syscap SystemCapability.ArkUI.ArkUI.Full
* @since 12
*/
iconSize: number | string;
}// File: button.d.ts (in @internal/component/ets/)
declare class ButtonAttribute extends CommonMethod<ButtonAttribute> {
// Existing methods...
/**
* Sets the icon size.
*
* @param value - Icon size in vp. Valid range: 0-100vp.
* If undefined, restores to default size (24vp).
* @unit vp
* @syscap SystemCapability.ArkUI.ArkUI.Full
* @since 12 dynamic
*/
iconSize(value: number | string | Length | undefined): ButtonAttribute;
}setFontSizefontSizedeclare class Text {
/**
* Font size.
*
* @type { number | string | Resource }
* @unit fp
* @syscap SystemCapability.ArkUI.ArkUI.Full
* @since 7
*/
fontSize: number | string | Resource;
/**
* Sets the font size.
*
* @param value - Font size value.
* @deprecated since 10. Use fontSize property instead.
* @see fontSize
* @syscap SystemCapability.ArkUI.ArkUI.Full
* @since 7
* @obsoleted 10
*/
setFontSize(value: number | string | Resource): void;
}// File: text.d.ts (in @internal/component/ets/)
declare class TextAttribute extends CommonMethod<TextAttribute> {
/**
* Sets the font size.
*
* @param value - Font size in fp. Valid range: 0-1000fp.
* @unit fp
* @syscap SystemCapability.ArkUI.ArkUI.Full
* @since 10 dynamic
*/
fontSize(value: number | string | Length | Resource | undefined | null): TextAttribute;
/**
* Sets the font size (deprecated method).
*
* @param value - Font size value.
* @deprecated since 10. Use fontSize() instead.
* @see fontSize
* @syscap SystemCapability.ArkUI.ArkUI.Full
* @since 7 dynamic
* @obsoleted 10
*/
setFontSize(value: number | string | Resource): TextAttribute;
}// ❌ Bad: Only static API defined
// File: text.static.d.ets
declare class Text {
content: string | Resource;
}
// Missing: @internal/component/ets/text.d.ts has no content() method
// ✅ Good: Both APIs synchronized
// File: text.static.d.ets
declare class Text {
content: string | Resource;
}
// File: text.d.ts (in @internal/component/ets/)
declare class TextAttribute extends CommonMethod<TextAttribute> {
content(value: string | Resource): TextAttribute;
}// ❌ Bad: Signatures don't match
// Static: .static.d.ets
iconSize: number;
// Dynamic: @internal/component/ets/*.d.ts
iconSize(value: number | string | Resource): ButtonAttribute; // Different types!
// ✅ Good: Consistent types
// Static: .static.d.ets
iconSize: number | string;
// Dynamic: @internal/component/ets/*.d.ts
iconSize(value: number | string): ButtonAttribute; // Matches// ❌ Bad: Missing null/undefined handling, constraints
/**
* Sets the width.
*/
width(value: number): CommonMethod;
// ✅ Good: Complete documentation
/**
* Sets the component width.
* @param value Width value in vp. Valid range: 0-10000vp.
* If undefined, restores default width.
* @unit vp
* @since 8
* @syscap SystemCapability.ArkUI.ArkUI.Full
*/
width(value: number | string | Length | undefined): CommonMethod;// ⚠️ Less optimal: Only accepts number/string
fontSize(value: number | string): TextAttribute;
// ✅ Better: Supports resource theming
fontSize(value: number | string | Length | Resource): TextAttribute;references/OpenHarmony-Application-Typescript-JavaScript-coding-guide.mdexamples/interface-definition.tsexamples/modifier-implementation.tsexamples/deprecation-pattern.tsexamples/static-dynamic-sync.tsdocs/sdk/Component_API_Knowledge_Base_CN.mddocs/sdk/ArkUI_SDK_API_Knowledge_Base.md/**
* Brief description.
* @param paramName Description including undefined/null behavior and constraints.
* @unit vp | fp | px (for length values)
* @throws {ErrorType} Description (when errors can occur)
* @since version static (for Static API - use "static" after version)
* @since version dynamic (for Dynamic API - use "dynamic" after version)
* @syscap SystemCapability.ArkUI.ArkUI.Full (system capability)
* @stagemodelonly (indicates this is a stage model only API)
* @deprecated Use alternativeMethod() instead (for deprecated APIs)
* @obsoleted version (when API was removed)
*/.static.d.ets@since X static@since 26 static*Modifier.d.ts@since X dynamic@since 26 dynamic@stagemodelonlyDoes the parameter accept length values?
├─ Yes → Add Length and Resource types
└─ No → Is it theme-able (color, size, string)?
├─ Yes → Add Resource type
└─ No → Use basic types (number | string | undefined | null)// Document defaults in JSDOC:
"If undefined, restores to default [value] ([unit])."
"If null, removes setting and uses inherited value."| Aspect | Static API ( | Dynamic API ( |
|---|---|---|
| File Location | | |
| Usage | | |
| Type | Class declaration | Class extending CommonMethod |
| Pattern | Constructor-based | Method chaining |
| Return Type | N/A (properties) | Concrete Attribute type |
| Version Tag | | |
| Both Required | ✅ Yes | ✅ Yes |
interface/sdk-js/api/arkui/component/*.static.d.etsinterface/sdk-js/api/@internal/component/ets/*.d.ts@since XX static@since XX dynamicButtonAttribute@since 26 static@since 26 dynamic// Static: richEditor.static.d.ets
default lineSpacing(value: LengthMetrics | undefined): this;
// Dynamic: rich_editor.d.ts
// Method is missing! ✗// Static: richEditor.static.d.ets
default lineSpacing(value: LengthMetrics | undefined, options?: LineSpacingOptions): this;
// Dynamic: rich_editor.d.ts
lineSpacing(value: LengthMetrics | undefined, options?: LineSpacingOptions): RichEditorAttribute;// Static:
default lineSpacing(value: LengthMetrics): this;
// Dynamic:
lineSpacing(value: LengthMetrics | undefined): RichEditorAttribute;
// ✗ Parameter types don't match!// Static:
default lineSpacing(value: LengthMetrics | undefined, options?: LineSpacingOptions): this;
// Dynamic:
lineSpacing(value: LengthMetrics | undefined, options?: LineSpacingOptions): RichEditorAttribute;
// ✓ Parameters match perfectly// Static: @since 26
// Dynamic: @since 26
// ✗ Missing static/dynamic specification// Static: @since 26 static
// Dynamic: @since 26 dynamic
// ✓ Clear distinction// Looking in: arkui/ButtonModifier.d.ts
// This file only defines Modifier class, not Attribute interface!// Dynamic API is in: @internal/component/ets/button.d.ts
// This file defines ButtonAttribute class with all methods