From 1aca02fd54ff2fa3d6cf97e17dbb9fd92936e609 Mon Sep 17 00:00:00 2001 From: Chris Reeves Date: Thu, 18 Mar 2021 17:49:07 -0400 Subject: [PATCH] add a few missing properties and adjust the extend and extendWith typings - #3367 --- typings/ractive.d.ts | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/typings/ractive.d.ts b/typings/ractive.d.ts index d4833b412..ca035ae7b 100644 --- a/typings/ractive.d.ts +++ b/typings/ractive.d.ts @@ -371,7 +371,7 @@ export class ContextHelper { unshift(keypath: string, value: any): ArrayPushPromise; } -export type Component = Static | Promise; +export type Component = Static | Promise>; export interface ComputationDescriptor = Ractive> { /** @@ -1025,6 +1025,7 @@ export interface Registries> { interpolators: Registry; helpers: Registry; partials: Registry; + transitions: Registry; } export interface Constructor, U extends InitOpts = InitOpts> { @@ -1035,7 +1036,7 @@ export interface Static = Ractive> { new = InitOpts>(opts?: V): T; /** The registries that are inherited by all instance. */ - defaults: Registries; + defaults: Registries & ValueMap; adaptors: Registry; components: Registry; @@ -1046,12 +1047,14 @@ export interface Static = Ractive> { interpolators: Registry; helpers: Registry; partials: Registry; + transitions: Registry; /** Create a new component with this constructor as a starting point. */ - extend = ExtendOpts>(opts?: V): Static>; + extend(): Static; + extend & ValueMap, U extends Readonly & ValueMap>>>(opts: A, ...more: U): Static>; /** Create a new component with this constructor as a starting point using the given constructor. */ - extendWith, V extends InitOpts = InitOpts, W extends ExtendOpts = ExtendOpts>(c: Constructor, opts?: W): Static>; + extendWith = InitOpts, W extends ExtendOpts = ExtendOpts>(c: Constructor, opts?: W): Static; /** Get a Context for the given node or selector. */ getContext(nodeOrQuery: HTMLElement | string): ContextHelper; @@ -1111,6 +1114,9 @@ export class Ractive = Ractive> { interpolators: Registry; helpers: Registry; partials: Registry; + transitions: Registry; + + readonly event?: ContextHelper|Event|any; /** When overriding methods, the original method is available using this._super. */ _super(...args: any[]): any; @@ -1532,12 +1538,14 @@ export class Ractive = Ractive> { static interpolators: Registry; static helpers: Registry; static partials: Registry; + static transitions: Registry; /** Create a new component with this constructor as a starting point. */ - static extend(opts?: ExtendOpts): Static>; + static extend(): Static; + static extend & ValueMap, U extends Readonly & ValueMap>>>(opts: T, ...more: U): Static>; /** Create a new component with this constructor as a starting point using the given constructor. */ - static extendWith, V extends InitOpts = InitOpts, W extends ExtendOpts = ExtendOpts>(c: Constructor, opts?: W): Static>; + static extendWith, V extends InitOpts = InitOpts, W extends ExtendOpts = ExtendOpts>(c: Constructor, opts?: W): Static; /** Get a Context for the given node or selector. */ static getContext(nodeOrQuery: HTMLElement | string): ContextHelper; @@ -1567,6 +1575,13 @@ export class Ractive = Ractive> { static Parent: Static; } +type Merge = { + 0: T; + 1: ((...t: U) => any) extends ((head: infer Head, ...tail: infer Tail) => any) + ? Merge & Head, Tail, X> + : never; +}[U['length'] extends 0 ? 0 : 1] + export module Ractive { /** The prototype for Context objects. You can use this to add methods and properties to Contexts. */ const Context: typeof ContextHelper; @@ -1581,8 +1596,18 @@ export module Ractive { /** true if Ractive detects that this environment supports svg. */ const svg: boolean; + /** The build version of Ractive. */ const VERSION: string; + /** Setting this to false will prevent Ractive from printing a welcome console message when the first instance is created. */ + let WELCOME_MESSAGE: false|undefined; + + /** + * Returns the current Ractive runloop Promise, if there is one. This is useful in callbacks that Ractive processes + * during update/render cycles, like observers and decorators. + */ + let tick: Promise; + /** * The current operation promise is available to things like observers and decorators using Ractive.tick, * which will return undefined if there is not currently an operation in progress.