> For the complete documentation index, see [llms.txt](https://ploegert.gitbook.io/til/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ploegert.gitbook.io/til/programmy/typescript/type-narrowing-with-similarly-shaped-objects.md).

# Type Narrowing With Similarly Shaped Objects

Let's say we have a type with several properties and a variable of that type.

```typescript
type User = {
  firstName: string
  lastName: string
  age: number
  email: string
}

const liz: User = {
  firstName: 'Liz',
  lastName: 'Lemon',
  age: 38,
  email: 'liz@example.com'
}
```

We can use variables of this type in *narrower* contexts as long as the properties that are present have aligning types.

For instance, we can pass a `User` to this `sendNewsletter` function. Even though the types don't match exactly, the type of `sendNewsletter`'s parameter is a subset of `User`.

```typescript
const sendNewsletter = ({
  firstName,
  email,
}: {
  firstName: string;
  email: string;
}) => {
  console.log(`Sending newsletter to ${firstName} at ${email}`);
};

sendNewsletter(liz);
// "Sending newsletter to Liz at liz@example.com"
```

This is a form of [*type narrowing*](https://www.typescriptlang.org/docs/handbook/2/narrowing.html) through [structural subtyping](https://www.typescriptlang.org/docs/handbook/type-compatibility.html).
