The Dto wrapper turns a class type into a data transfer object type by removing all the methods from the type definition, thereby creating a type that has only data properties. It further makes all the data properties optional.

When receiving an object transferred across a network, make sure to wrap its class type in a Dto. This lets the type checker know that the object will have the class's data but not the class's methods, and that it might not have all of the data properties.

type DataPropertyNames<T> = {
  [K in keyof T]: T[K] extends Function ? never : K;
}[keyof T];

type DataPropertiesOnly<T> = {
  [P in DataPropertyNames<T>]?: T[P] extends object ? Dto<T[P]> : T[P]

export type Dto<T> = DataPropertiesOnly<T>;

In the image, the dto object only has the data property names.