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

bug: #[ts(optional)] does not work with Option type alias #380

Closed
gustavo-shigueo opened this issue Feb 20, 2025 · 1 comment · Fixed by #366
Closed

bug: #[ts(optional)] does not work with Option type alias #380

gustavo-shigueo opened this issue Feb 20, 2025 · 1 comment · Fixed by #366
Labels
bug Something isn't working

Comments

@gustavo-shigueo
Copy link
Collaborator

This is a rewording of #379 focusing on Option not working properly if spelled any other way rather than making optional work with any type

Describe the bug
Whenever the Option type is spelled out as anything other than the word Option by itself, the #[ts(optional)] attribute fails to
recognize it as an Option, this is because of the extract_option_argument function, which expects the type to have only one
component, and expects that component to be the word Option with one generic argument.

This means spelling Option as core::option::Option (which is quite important for macros) or std::option::Option or creating some type
alias type Foo<T> = Option<T> and using the type Foo will cause compiler errors when using #[ts(optional)]

To Reproduce
Steps to reproduce the behavior:

  1. Create the following type:
type Opt<T> = Option<T>;

#[derive(TS)]
struct Foo {
  a: Option<T>, // Works
  b: core::option::Option<i32>, // Error
  c: std::option::Option<i32>, // Error
  d: Opt<i32>, // Error
}

Version
10.1

There is already a fix for this issue in #366, but this PR is a breaking change and still needs approval

@gustavo-shigueo gustavo-shigueo added the bug Something isn't working label Feb 20, 2025
@gustavo-shigueo gustavo-shigueo linked a pull request Feb 20, 2025 that will close this issue
3 tasks
@gustavo-shigueo
Copy link
Collaborator Author

Turns out this is the last remnant of #70, as type aliasing hasn't been an issue since all the way back in #233

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant