TS2352

Conversion of type '{ name: string; age: number; }' to type 'Person' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.

Broken Code ❌

type Person = {
  firstName: string;
  age: number;
};
 
const myObject = {
  name: 'Benny',
  age: 34,
} as Person;

Fixed Code ✔️

Make sure all properties of your object match the properties of your declared type:

type Person = {
  firstName: string;
  age: number;
};
 
const myObject = {
  firstName: 'Benny',
  age: 34,
} as Person;

Alternative but not recommended: Convert your object to unknown first:

type Person = {
  firstName: string;
  age: number;
};
 
const myObject = {
  name: 'Benny',
  age: 34,
} as unknown as Person;