Function: defineExtension()
defineExtension<
Config
,Name
,Output
,Init
>(extension
):LexicalExtension
<Config
,Name
,Output
,Init
>
Define a LexicalExtension from the given object literal. TypeScript will infer Config and Name in most cases, but you may want to use safeCast for config if there are default fields or varying types.
Type Parameters
• Config extends ExtensionConfigBase
• Name extends string
• Output
• Init
Parameters
• extension: LexicalExtension
<Config
, Name
, Output
, Init
>
The LexicalExtension
Returns
LexicalExtension
<Config
, Name
, Output
, Init
>
The unmodified extension argument (this is only an inference helper)
Examples
export const MyExtension = defineExtension({
// Extension names must be unique in an editor
name: "my",
nodes: [MyNode],
});
export interface ConfigurableConfig {
optional?: string;
required: number;
}
export const ConfigurableExtension = defineExtension({
name: "configurable",
// The Extension's config must satisfy the full config type,
// but using the Extension as a dependency never requires
// configuration and any partial of the config can be specified
config: safeCast<ConfigurableConfig>({ required: 1 }),
});
Defined in
lexical-builder-core/dist/defineExtension.d.ts:34