fix(napi-derive): invalid TypeScript return type

This commit is contained in:
LongYinan 2022-04-27 18:19:38 +08:00
parent 2fecc109ef
commit 44b4cc34e0
No known key found for this signature in database
GPG key ID: C3666B7FC82ADAD7
6 changed files with 12 additions and 9 deletions
crates/backend/src

View file

@ -181,6 +181,7 @@ static KNOWN_TYPES: Lazy<HashMap<&'static str, &'static str>> = Lazy::new(|| {
("Either5", "{} | {} | {} | {} | {}"),
("unknown", "unknown"),
("Null", "null"),
("JsNull", "null"),
("null", "null"),
("Symbol", "symbol"),
("JsSymbol", "symbol"),
@ -262,7 +263,7 @@ pub fn ty_to_ts_type(ty: &Type, is_return_ty: bool, is_struct_field: bool) -> (S
if is_struct_field {
arg.to_string()
} else if is_return_ty {
format!("{}?", arg)
format!("{} | null", arg)
} else {
format!("{} | undefined | null", arg)
},