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

Autocomplete event names on JS side #25

Open
Laegel opened this issue Feb 9, 2021 · 1 comment
Open

Autocomplete event names on JS side #25

Laegel opened this issue Feb 9, 2021 · 1 comment
Labels
enhancement New feature or request

Comments

@Laegel
Copy link
Member

Laegel commented Feb 9, 2021

JS relies heavily on strings which can lead to typo issues.
The idea would be to look for events that Rust emits in the code so we have a list of available events on JS side.
Maybe even show some error waves under invalid names like following

Rust
image

JS
image

Thanks to MGlolenstine for the idea. 👍

@Suyashtnt
Copy link

if you are using typescript heres something i made for glowsquid-launcher/glowsquid

import { invoke as tauriInvoke } from "@tauri-apps/api";
import type { Object } from "ts-toolbelt";

type FunctionType = (arg: Record<string, unknown>) => unknown;

interface InvokeMap extends Record<string, FunctionType> {
  "do_something"(args: {argument: string}): string;
}

export default function invoke<
  T extends InvokeMap,
  C extends Object.SelectKeys<
    T,
    FunctionType
  >,
>(c: C, args: Parameters<T[C]>[0] ): Promise<ReturnType<T[C]>> {
  return tauriInvoke(c, args);
}

you get errors during compile time and autocomplete inside vscode

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

No branches or pull requests

2 participants