In TypeScript there is a `Pick` type which lets yo...
# announcements
v
In TypeScript there is a
Pick
type which lets you easily (and type-safe) define sub-shape:
Copy code
interface Todo {
    title: string;
    description: string;
    completed: boolean;
}

type TodoPreview = Pick<Todo, 'title' | 'completed'>; // you can only specify properties of Todo here

const todo: TodoPreview = {
    title: 'Clean room',
    completed: false,
};
I'm trying to find out whether it's possible to achieve something like this in Kotlin
k
Not really, but you can define interfaces and separate data classes of course.
t
a sealed class hierarchy might achieve what you want
v
not the case, I want to use java classes as source
t
I’m not sure I follow then
v
see the example in the chat
t
You could create your own builder for it then
But you could also mirror your types in a sealed class hierarchy to achieve it
Or write an annotation processor
v
yep, I cannot find anything better then annotation processor
still not clear how to make compile time property check
a
I'm not sure if a Pick-like construct is very useful in a non-structural typing system though?
v
I brought it just to demonstrate property referencing