deep partial typescript 1

deep partial typescript

//You can simply create a new type, say, DeepPartial, which basically references itself:
type DeepPartial = {
    [P in keyof T]?: DeepPartial;
};

//Then, you can use it as such:
const foobar: DeepPartial = {
  foo: 1,
  bar: { baz: true }
};

Here is what the above code is Doing:
1. We create a new type, DeepPartial, which references itself.
2. We use the DeepPartial type to create a new type, foobar, which is a DeepPartial of Foobar.
3. We create a new object, foobar, which is of type DeepPartial.

Similar Posts