Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript definitions #55

Open
Benni08 opened this issue Mar 13, 2024 · 2 comments
Open

Typescript definitions #55

Benni08 opened this issue Mar 13, 2024 · 2 comments

Comments

@Benni08
Copy link

Benni08 commented Mar 13, 2024

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
Copy link
Owner

Eilon commented Mar 13, 2024

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
Copy link

yamachu commented Mar 18, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants