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

Better TS type formatting for array types #4346

Merged
merged 2 commits into from
Dec 9, 2024

Conversation

RunDevelopment
Copy link
Contributor

Small PR. If the TS item type of an array is a valid identifier, we don't need to the parens.

FYI, the parens are necessary for imported types. Imported types can specify an arbitrary TS type expression as their TS type.

Copy link
Collaborator

@daxpedda daxpedda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, the parens are necessary for imported types. Imported types can specify an arbitrary TS type expression as their TS type.

What is an "arbitrary TS type expression"?
Why can that contain invalid Unicode (if I'm interpreting the code correctly)?
Can we have a test for something like this or is there one already?

@RunDevelopment
Copy link
Contributor Author

What is an "arbitrary TS type expression"?

Anything that isn't just a plain identifier. E.g. number | string. Absent the ability to specify custom types for parameters and return types, people are currently using this workaround:

#[wasm_bindgen]
extern "C" {
    #[wasm_bindgen(typescript_type = "number | string")]
    type CustomType;
}

#[wasm_bindgen]
pub fn single(a: CustomType) {}

I added a test.

Why can that contain invalid Unicode (if I'm interpreting the code correctly)?

By the guarantees of str, obviously no. What in the code gave you that idea? (Because I just moved the stuff that we already had.)

Copy link
Collaborator

@daxpedda daxpedda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Why can that contain invalid Unicode (if I'm interpreting the code correctly)?

By the guarantees of str, obviously no. What in the code gave you that idea? (Because I just moved the stuff that we already had.)

I didn't understand what is_valid_ident() actually does. But I had a proper read now.

@daxpedda daxpedda merged commit f1e2d6e into rustwasm:main Dec 9, 2024
67 checks passed
@RunDevelopment RunDevelopment deleted the vec-item-ident branch December 11, 2024 16:59
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

Successfully merging this pull request may close these issues.

2 participants