Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Argument of type partial is not assignable to parameter of type

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?

like image 277
Lara Avatar asked Sep 13 '25 16:09

Lara


2 Answers

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;
like image 100
JBD Avatar answered Sep 15 '25 07:09

JBD


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.

like image 36
Alex Wayne Avatar answered Sep 15 '25 06:09

Alex Wayne