---
lang: en
title: 'API docs: context.asserttargettype'
keywords: LoopBack 4.0, LoopBack 4, Node.js, TypeScript, OpenAPI
sidebar: lb4_sidebar
editurl: https://github.com/loopbackio/loopback-next/tree/master/packages/context
permalink: /doc/en/lb4/apidocs.context.asserttargettype.html
---

<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@loopback/context](./context.md) &gt; [assertTargetType](./context.asserttargettype.md)

## assertTargetType() function

Assert the target type inspected from TypeScript for injection to be the expected type. If the types don't match, an error is thrown.

**Signature:**

```typescript
export declare function assertTargetType(injection: Readonly<Injection>, expectedType: Function, expectedTypeName?: string): string;
```

## Parameters

<table><thead><tr><th>

Parameter


</th><th>

Type


</th><th>

Description


</th></tr></thead>
<tbody><tr><td>

injection


</td><td>

Readonly&lt;[Injection](./context.injection.md)<!-- -->&gt;


</td><td>

Injection information


</td></tr>
<tr><td>

expectedType


</td><td>

Function


</td><td>

Expected type


</td></tr>
<tr><td>

expectedTypeName


</td><td>

string


</td><td>

_(Optional)_ Name of the expected type to be used in the error


</td></tr>
</tbody></table>
**Returns:**

string

The name of the target


