feat(KT-48814): represent all of the external declarations nullable properties as an optional fields inside d.ts.

This commit is contained in:
Artem Kobzar
2022-09-02 10:50:20 +00:00
committed by Space
parent a52d8f0364
commit 0bb0be8703
12 changed files with 41 additions and 8 deletions
@@ -59,6 +59,7 @@ class ExportedProperty(
val isField: Boolean = false,
val irGetter: IrFunction? = null,
val irSetter: IrFunction? = null,
val isOptional: Boolean = false
) : ExportedDeclaration()
// TODO: Cover all cases with frontend and disable error declarations
@@ -139,6 +139,9 @@ class ExportModelGenerator(val context: JsIrBackendContext, val generateNamespac
specializeType: ExportedType? = null
): ExportedDeclaration {
val parentClass = property.parent as? IrClass
val isOptional = property.isEffectivelyExternal() &&
property.parent is IrClass &&
property.getter?.returnType?.isNullable() == true
return ExportedProperty(
name = property.getExportedIdentifier(),
@@ -149,7 +152,8 @@ class ExportModelGenerator(val context: JsIrBackendContext, val generateNamespac
isProtected = property.visibility == DescriptorVisibilities.PROTECTED,
isField = parentClass?.isInterface == true,
irGetter = property.getter,
irSetter = property.setter
irSetter = property.setter,
isOptional = isOptional
)
}
@@ -133,7 +133,8 @@ class ExportModelToTsDeclarations {
""
} else {
val readonly = if (isMember && !mutable) "readonly " else ""
"$prefix$visibility$possibleStatic$keyword$readonly$memberName: $typeToTypeScript;"
val optional = if (isOptional) "?" else ""
"$prefix$visibility$possibleStatic$keyword$readonly$memberName$optional: $typeToTypeScript;"
}
}
}