I am trying to update partial property of one of interface in TypeScript as below
interface details{
name: string,
phonenumber: number,
IsActive: boolean
}
let pDt: Partial<details> = {IsActive: false};
and when i am trying to pass it one of the method which has details
as parameter, it is giving below issue "Argument of type Partial is not assignable to parameter of type 'detail'".
What's wrong here and how to correct?
You can, in your case if you want to use Partial, cast it like this:
interface Details{
name: string,
phonenumber: number,
IsActive: boolean
}
let partialDetails: Partial<Details> = {IsActive: false};
let details: Details = partialDetails as Details;
Argument of type Partial is not assignable to parameter of type 'detail'
You can't assign a Partial of a type to the original type you made the partial from.
interface Details{
name: string,
phonenumber: number,
IsActive: boolean
}
let partialDetails: Partial<Details> = {IsActive: false};
let details: Details = partialDetails // error
Playground
This makes sense because Details
expects a value on all properties, but Partial<Details>
can omit any of those properties. This makes the partial incompatible with the whole type you made a partial of.
There's no easy "fixing" this. It depends on your app's logic. If you have a function that expects a whole Details
then you have to pass it a whole Details
, a Partial<Details>
will not do.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With