Skip to content

ExtractConstructor<T>

Unofficial

Extracts a constructor type from an interface that defines a constructor__, constructor2__, constructor3__, constructor4__, or constructor5__ method.

Prefers higher-numbered variants over lower-numbered ones when multiple are present, since higher-numbered variants represent deeper subclass constructors when ancestor classes already define lower-numbered ones.

The constructor[N]__ helpers are declared optional (constructor[N]__?), so matching is done via 'constructor[N]__' extends keyof T (which sees optional keys) combined with NonNullable (which strips the | undefined an optional member carries), rather than T extends \{ constructor[N]__(): … \} (which no longer matches an optional method). The final branch still accepts a function type passed directly (e.g. ExtractConstructor<App['constructor__']>), NonNullable likewise tolerating its optional | undefined.

Import:

import type { ExtractConstructor } from '@obsidian-typings/obsidian-catalyst-latest';

Example:

// From an interface:
type AppCtor = ExtractConstructor<App>;
// From a constructor__ method type directly:
type AppCtor = ExtractConstructor<App['constructor__']>;

Signature:

export interface ExtractConstructor<T>

Links to this page: