Skip to main content

Function: getNativeInterface()

getNativeInterface<T>(obj, iface): T | null

Defined in: packages/ffi/src/native/object.ts:111

Gets a native object as a specific interface type if it implements that interface.

Uses GLib's type system to check if the object implements the specified interface, and returns a wrapped instance if it does.

Type Parameters

Type ParameterDescription
T extends NativeObjectThe interface type

Parameters

ParameterTypeDescription
objNativeObjectThe native object to check
ifaceNativeClass<T>The interface class (must have a glibTypeName property)

Returns

T | null

The wrapped interface instance, or null if not implemented

Example

const editable = getNativeInterface(widget, Gtk.Editable);
if (editable) {
const text = editable.getText();
}