Skip to content

Add TypeScript typings?Β #103

@JacobEvelyn

Description

@JacobEvelyn

This seems to work for me, but I'm a TypeScript beginner and am probably doing a lot of things wrong:

// Modified from https://github.com/patrick-steele-idem/morphdom/pull/113/commits/0b6b2e87b5f1b193c40c4c64f25938846ccd4039
declare module "nanomorph" {
  interface NanomorphOptions {
    getNodeKey?: (node: Node) => any;
    onBeforeNodeAdded?: (node: Node) => Node;
    onNodeAdded?: (node: Node) => Node;
    onBeforeElUpdated?: (fromEl: HTMLElement, toEl: HTMLElement) => boolean;
    onElUpdated?: (el: HTMLElement) => void;
    onBeforeNodeDiscarded?: (node: Node) => boolean;
    onNodeDiscarded?: (node: Node) => void;
    onBeforeElChildrenUpdated?: (
      fromEl: HTMLElement,
      toEl: HTMLElement
    ) => boolean;
    childrenOnly?: boolean;
  }

  namespace nanomorph {

  }

  function nanomorph(
    fromNode: Node,
    toNode: Node | string,
    options?: NanomorphOptions
  ): void;

  export default nanomorph; // Added "default" here.
}

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