Skip to content

Declare type for the options parameter of the mount() function on its own #13655

@webJose

Description

@webJose

Describe the problem

For declaring ambient modules and even regular types for code that uses mount() and would like to type things, the type for the options parameter is not named, and instead is defined inline:

 * @param {{} extends Props ? {
 * 		target: Document | Element | ShadowRoot;
 * 		anchor?: Node;
 * 		props?: Props;
 * 		events?: Record<string, (e: any) => any>;
 * 		context?: Map<any, any>;
 * 		intro?: boolean;
 * 	}: {
 * 		target: Document | Element | ShadowRoot;
 * 		props: Props;
 * 		anchor?: Node;
 * 		events?: Record<string, (e: any) => any>;
 * 		context?: Map<any, any>;
 * 		intro?: boolean;
 * 	}} options

Describe the proposed solution

Declare the options parameter's type as its own type:

 export type MountOptions<Props extends Record<string, any> = Record<string, any>> = {} extends Props ? {
 		target: Document | Element | ShadowRoot;
 		anchor?: Node;
 		props?: Props;
 		events?: Record<string, (e: any) => any>;
 		context?: Map<any, any>;
 		intro?: boolean;
 	}: {
 		target: Document | Element | ShadowRoot;
 		props: Props;
 		anchor?: Node;
 		events?: Record<string, (e: any) => any>;
 		context?: Map<any, any>;
 		intro?: boolean;
 	}

BTW, now that I see the type, maybe the following is more succinct?

export type MountOptions<Props extends Record<string, any> = Record<string, any>> = {
  target: Document | Element | ShadowRoot;
  anchor?: Node;
  events?: Record<string, (e: any) => any>;
  context?: Map<any, any>;
  intro?: boolean;
} & {} extends Props ? {
  props?: Props;
} : {
  props: Props;
}

Importance

nice to have

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions