Skip to content

More precise typescript types #32

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

Closed
matheus23 opened this issue Jun 28, 2022 · 1 comment · Fixed by #35
Closed

More precise typescript types #32

matheus23 opened this issue Jun 28, 2022 · 1 comment · Fixed by #35
Labels
enhancement New feature or request

Comments

@matheus23
Copy link
Member

Summary

The typescript types generated from wasm-bindgen aren't very precise, see for example:

/**
* Returns the name and metadata of the direct children of a directory.
* @param {Array<any>} path_segments
* @param {any} store
* @returns {Promise<any>}
*/
  ls(path_segments: Array<any>, store: any): Promise<any>;

I think path_segments could be Array<string>, and store: ForeignBlockStore?

Problem

This helps orient users using TS types for autocompletion in IDEs, for example. Also makes sure that there are fewer accidental runtime errors.

Impact

Not big, only people using the wnfs npm package. Which is mostly me at the moment. I think it's fair to expect anyone else to use webnative, not wnfs directly.

Solution

I don't know. Maybe a setting in wasm-bindgen? Something that needs to be configured? Is that perhaps an issue with wasm-bindgen and they need to fix it?

@matheus23 matheus23 added the enhancement New feature or request label Jun 28, 2022
@appcypher
Copy link
Member

Found a solution to this.

rustwasm/wasm-bindgen#1197 (comment)

We could have a types.rs file for the type annotations

#[wasm_bindgen(typescript_custom_section)]
const TS_BLOCKSTORE: &'static str = r#"
export interface BlockStore {
    putBlock(bytes: string): Promise<Uint8Array>;
    getBlock(cid: Uint8Array): Promise<Uint8Array>;
}
"#;
#[wasm_bindgen]
extern "C" {
    #[wasm_bindgen(typescript_type = "BlockStore")]
    pub type BlockStore;

    // ...
}

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

Successfully merging a pull request may close this issue.

2 participants