Skip to content

React template has a bunch of type safety errors #47

@rafikhan

Description

@rafikhan

When I create a brand new project with bolt-uxp using with react it shows a bunch of type safety errors pop up. The project still builds and runs but the errors are annoying. There are a bunch of things wrong with it, rather than spell it all out, here is my suggestion:

  1. Rename vite-env.d.ts to uxp-env.d.ts
  2. Consolidate all augmentations to this file.
  3. Use the definitions below (it works in my codebase)
/// <reference types="vite/client" />

declare global {
  interface Window {
    webview: import("@adobe/cc-ext-uxp-types/uxp/index").HTMLWebViewElement;
  }

  /**
   * UXP Webview Element Type
   * Extends HTMLElement with UXP-specific webview properties and methods
   */
  interface UXPHTMLWebViewElement extends HTMLElement {
    uxpAllowInspector: string;
    src: string;
    postMessage: (msg: any) => void;
  }
}

// Augment the JSX namespace for react-jsx runtime
declare module "react/jsx-runtime" {
  namespace JSX {
    interface IntrinsicElements {
      "uxp-panel": import("react").DetailedHTMLProps<
        import("react").HTMLAttributes<HTMLElement> & { panelid?: string },
        HTMLElement
      >;
      "webview": import("react").DetailedHTMLProps<
        import("react").HTMLAttributes<UXPHTMLWebViewElement>,
        UXPHTMLWebViewElement
      >;
    }
  }
}

export {};

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