Re: Subclassing a GObject in Typescript



A generic seems appropriate, here's how you can start:

```ts
export function registerClass<T>(klass: T): T & Partial<{
  [interfaces]: any[]
  [properties]: any
  [requires]: any[]
  [signals]: any
}>`
```

Best not leave it with `any` but specify what types these properties should have.

_init should receive `${name}_ConstructProps` for proper checking, not just any object. Look for the push of "default constructor", and add the _init definition nearby, that should be enough.

On 2018-11-16 15:56, Tony Houghton wrote:
I want to make ts-for-gjs work with registerClass(), but as a
Typescript beginner I would appreciate some advice. I'm proposing to
make it add these globals to GObject.d.ts:

export function registerClass(klass: Object): Object
export declare const interfaces: unique symbol
export declare const properties: unique symbol
export declare const requires: unique symbol
export declare const signals: unique symbol

Does that look OK? I'm not 100% sure that Object is the most
appropriate type to use for registerClass' parameter and return value.

GObject.Object needs this pseudo-constructor:

    _init(params?:object): void

but is the base class the only one that needs that, or is it
overridden in all subclasses?

When registerClass() is called, it adds the equivalent of these static
members to the class being registered:

    static [interfaces]?: any[]
    static [properties]?: object
    static [requires]?: any[]
    static [signals]?: object

Seeing as they're added dynamically to 3rd party classes, but aren't
present in the introspected classes, I don't think we can actually get
ts-for-gjs to do anything about them. Any ideas on how these could be
made convenient to use in Typescript?

--

TH
_______________________________________________
javascript-list mailing list
javascript-list gnome org
https://mail.gnome.org/mailman/listinfo/javascript-list


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]