MauiHybridWebView icon indicating copy to clipboard operation
MauiHybridWebView copied to clipboard

Typescript definitions

Open Benni08 opened this issue 1 year ago • 2 comments
trafficstars

Just Trying to use it with a React Typescript SPA, but i don't get the javascript working in a typescript.

Already tried to make a global.d.ts, and make there the extends Operation to Window interface, but i get some Compiler Errors.

Can anybody help?

Benni08 avatar Mar 13 '24 06:03 Benni08

Hi, that would be a good area to improve for HybridWebView. Unfortunately I'm not very familiar with how this works with TypeScript or React, so if anyone can offer suggestions on how to do this, it'd be greatly appreciated!

Eilon avatar Mar 13 '24 19:03 Eilon

Hi @Benni08

In my sample project, I am using the following type definition and calling it from React. The key points here as follows

  • Type definition for window global in the hooks file.

https://github.com/yamachu/PokedexWithDotnetWebTechnologies/blob/73be030054d6a78b7e9f4921a9f6b0d21a480a78/react/packages/interop-hybridwebview/src/hooks/useHybridWebView.ts#L4-L8

This is the case when offered as a separate package, but of course it is also possible to offer them together as a single package. Type definitions can be enabled by creating a types directory, for example, and creating a d.ts file like the following

src/types/global.d.ts

export declare global {
  interface Window {
    HybridWebView: HybridWebView;
  }
}

type HybridWebView = {
  // actual HybridWebView types...
}

yamachu avatar Mar 18 '24 13:03 yamachu