Hello all, is there a way to do Partial<TypeNam...
# getting-started
n
Hello all, is there a way to do Partial<TypeName> like in TypeScript? I saw this question already asked on [stack overflow](https://stackoverflow.com/questions/50651879/kotlin-feature-like-typescript-partial) but its unanswered. My use case is having a
data class User(name: String, pass: String, email: String, etc...)
and then an update method which would take a Partial User so that you'd only have to supply a subset of the fields
fun update(user: Partial<User>): User {...}
. Should I just create a new type for this? Such as
data class PartialUser(name?: String = null, pass?: String = null, email: String = null, etc...)
.
s
You’ll have to create a second type, yes
👍 1
n
Thanks, good to know what's possible/isn't possible. I ended up creating separate types for create/update in the end. I think its better than partial anyway because their accepted fields vary slightly.
i
I have a codegen that handles this. You add a
@PartialDataObjects(["Partial","Create","Update"])
annotation to a data object X and it will create
PartialX
,
CreateX
,
UpdateX
data objects for you. it’s not totally ready for public consumption but i’ve found it super handy for my own projects if you’re interested: https://github.com/stardogventures/stardao/tree/master/stardao-kotlin-partial