If I have a type:
type MyType = {
...
propertyA: string;
propertyB: number;
...
}
how can I type this in another type but allow all versions of it with properties omitted? Such as:
type MyOtherType = {
propertyC: MyType | Omit<MyType, ANYTHING>;
}
I have tried Omit<MyType, any>
but that removes the types of other properties on the object.
What is the correct way to do this?
2
Answers
I believe you means make all of them optional (
Partial
), you can try to usePartial<T>
instead:If i understood correctly. You might use the
Partial
utility type to make all props of MyType optional and then use Omit to remove any property you want from it.It is an example. So I removed
propertyA
from MyType. You can remove other property with replacing ‘propertyA’ with the name of that property.