---
url: /docs/guide/usage/linter/rules/typescript/no-unsafe-class-instance-assignment.md
---

### What it does

Disallows using structurally compatible values where an instance of a class
or one of its subclasses is expected. It also checks values nested in types
such as arrays and promises.

### Why is this bad?

TypeScript's structural typing can accept an object with the same public
members as a class instance. The object can bypass initialization in the
class constructor and fail an `instanceof` check.

### Examples

Examples of **incorrect** code for this rule:

```ts
class Session {
  constructor(readonly id: string) {}
}

const session: Session = { id: "guest" };
```

Examples of **correct** code for this rule:

```ts
class Session {
  constructor(readonly id: string) {}
}

const session: Session = new Session("guest");
```

## How to use

## Version

This rule was added in vnext.

## References
