如何在 Reinforced.Typings 中将属性标记为可空(“type | null”)?

Mar*_*ski 5 reinforced-typings

Reinforced.Typings在属性ForceNullable上有参数[TsProperty],但它生成可选属性,并且我的 API 返回文字null(不要省略该属性或将其设置为undefined)。

例如,[TsProperty(ForceNullable = true)] field:boolean成为field?:boolean并且我希望它是field:boolean | null

使用 Reinforced.Typings 可以实现这一目标吗?

我不想使用像这样的解决方法[TsProperty(Type = "boolean | null")],我希望 c# typename 到 ts typename 由标准 Reinforced.Typings 逻辑处理,只需添加| null到结果类型。

Tim*_*Tim 1

可空值类型很简单。引用类型至少需要一个访问者,因为您必须使用相当复杂的反射来查看它是否可为空。

但对于像你的例子这样的 bool :

builder.SubstituteGeneric(typeof(Nullable<>),(t, r) => new RtSimpleTypeName($"{r.ResolveTypeName(t.GenericTypeArguments.First())} | null"));
Run Code Online (Sandbox Code Playgroud)