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

Javascript API types incorrect when reading physical size #2599

Closed
TomzBench opened this issue Sep 13, 2021 · 8 comments · Fixed by #2621
Closed

Javascript API types incorrect when reading physical size #2599

TomzBench opened this issue Sep 13, 2021 · 8 comments · Fixed by #2621
Labels
good first issue Good for newcomers priority: 1 high scope: api.js The @tauri-apps/api npm package type: bug

Comments

@TomzBench
Copy link

When using the Tauri API in typescript, the intellisense is not correct, (and therefore the typescript declarations are wrong?) Specifically the API I notice this issue is when reading the physical size.

const size = await api.window.appWindow.innerSize(); // { height: yyy, width: xxx}
size.toLogical(...); // <--- [Error] toLogical does not exist on size

My guess is that when sending the rust props over to javascript, the prototypes or methods are lost and only the values are passed. However the typescript typings are assuming you have a constructed object.

@amrbashir
Copy link
Member

toLogical doesn't communicate with rust at all, what is the type of size

@TomzBench
Copy link
Author

toLogical doesn't communicate with rust at all, what is the type of size

The actual type returned by innerSize() is a plain object with keys height and width. However, typescript thinks the object returned from innerSize() is aPhysicalSize object which is a class with methods that has atoLogical method. So i think the mapping between Tauri backend and the javascript frontend types is off.

@amrbashir
Copy link
Member

if typescript thinks the object is PhysicalSize and it has toLogical() method, then I see no problem as this is the intended behavior.

Tauri's backend and Rust has no role in this as toLogical() is purely executed in js only.

@FabianLars
Copy link
Member

No, the problem is, the function is defined as async innerPosition(): Promise<PhysicalPosition>, but instead of an instance of the PhysicalSize class (window.ts#L116-130) it returns a plain {width: a, height: b}

@TomzBench
Copy link
Author

if typescript thinks the object is PhysicalSize and it has toLogical() method, then I see no problem as this is the intended behavior.

Tauri's backend and Rust has no role in this as toLogical() is purely executed in js only.

The return type is wrong in the javascript function. You can either make the javascript create a new instance of a PhysicalSize and return this. Or change the return type.

@amrbashir
Copy link
Member

amrbashir commented Sep 13, 2021

Ah yes, I see the problem now, we are indeed just returning a plain object instead of an instance of a class.

Should've read your words more carefully, apologies.

@amrbashir amrbashir added scope: api.js The @tauri-apps/api npm package type: bug priority: 1 high good first issue Good for newcomers labels Sep 13, 2021
@sirgallifrey
Copy link
Contributor

If there isn't anyone already working on it, I'll give it a shot as my first contribution

@lemarier
Copy link
Member

If there isn't anyone already working on it, I'll give it a shot as my first contribution

It's all yours! Do not hesitate if you have any questions! You can reach us on discord as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers priority: 1 high scope: api.js The @tauri-apps/api npm package type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants