-
-
Notifications
You must be signed in to change notification settings - Fork 240
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
Document about EitherN
and correct handling of undefined
and null
#1986
Comments
Latest 2.16.0 release breaks: web-infra-dev/rspack#5811 This is not debuggable, we cannot figure out which key / value is erroneous
|
The Rspack CI was broken by #1971. The cause of confusion lies in |
A documentation around |
Hi! I'm the author of #1971. I believe the implementation is compatible with previous versions so I'm not sure why the tests are broken, but I can provide some information about By default (without specifying As for Therefore, to make a field both optional and nullable ( Here are more examples. To generate the following interface: interface Foo {
required2: null | string
required3: null | undefined | string
required4: null | undefined | string | boolean
optional2?: null | string
optional3?: null | undefined | string
optional4?: null | undefined | string | boolean
} you can define the following struct in Rust: #[napi(object)]
pub struct Foo {
pub required2: Either<Null, String>,
pub required3: Either3<Null, Undefined, String>,
pub required4: Either4<Null, Undefined, String, bool>,
pub optional2: Option<Either<Null, String>>,
pub optional3: Option<Either3<Null, Undefined, String>>,
pub optional4: Option<Either4<Null, Undefined, String, bool>>,
} |
Recent releases broke Rspack's tests twice, with confusing runtime error messages like "Value is non of these types
bool
,String
without context".It was suggested to use
Either4<Null, Undefined, String, bool>
, but quick search ofEither4
on napi.rs yields no results.I suggest we add some usage examples for the following typing cases:
foo: null | string
foo: null | undefined | string
foo?: null | string
I have no idea how they should work with Rust's
Option
type, is itfoo: Option<Undefined>
orfoo: Option<Either<Null, Undefined>>
? 🤔The text was updated successfully, but these errors were encountered: