Eilon / MauiHybridWebView

MIT License
200 stars 40 forks source link

Typescript definitions #55

Open Benni08 opened 3 months ago

Benni08 commented 3 months ago

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?

Eilon commented 3 months ago

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!

yamachu commented 3 months ago

Hi @Benni08

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

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...
}