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

[feat] Generate a d.ts file for @tauri-apps/api/core:invoke #9589

Closed
alex-way opened this issue Apr 27, 2024 · 1 comment
Closed

[feat] Generate a d.ts file for @tauri-apps/api/core:invoke #9589

alex-way opened this issue Apr 27, 2024 · 1 comment

Comments

@alex-way
Copy link

Describe the problem

There isn't any type safety for the invoke function, so it's extremely easy to pass invalid arguments.

Describe the solution you'd like

I think it would be great if rust could generate a d.ts file with the different registered handlers.

This should be possible by creating a d.ts file in the root of the "frontend" src like so:

declare module "@tauri-apps/api/core" {
	export function invoke<T>(
		cmd: "greet",
		args: {name: string},
		options?: unknown,
	): Promise<T>;

    export function invoke<T>(
		cmd: "meet",
		args: {greeting: string},
		options?: unknown,
	): Promise<T>;

// Optionally exclude this to provide stricter type safety
    export function invoke<T>(
		cmd: string,
		args?: unknown,
		options?: unknown,
	): Promise<T>;
}

There may be a better way to provide type safety but this was just my initial thoughts.

Alternatives considered

No response

Additional context

No response

@FabianLars
Copy link
Member

Duplicate of #1514, thanks for the feature request.

@FabianLars FabianLars closed this as not planned Won't fix, can't repro, duplicate, stale Apr 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants