feat(KT-48814): represent all of the external declarations nullable properties as an optional fields inside d.ts.
This commit is contained in:
@@ -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
|
||||
|
||||
+5
-1
@@ -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
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -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;"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user