---
lang: en
title: 'API docs: context.asserttargettype'
keywords: LoopBack 4.0, LoopBack 4
sidebar: lb4_sidebar
editurl: https://github.com/strongloop/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.

<b>Signature:</b>

```typescript
export declare function assertTargetType(injection: Readonly<Injection>, expectedType: Function, expectedTypeName?: string): string;
```

## Parameters

|  Parameter | Type | Description |
|  --- | --- | --- |
|  injection | <code>Readonly&lt;Injection&gt;</code> | Injection information |
|  expectedType | <code>Function</code> | Expected type |
|  expectedTypeName | <code>string</code> | Name of the expected type to be used in the error |

<b>Returns:</b>

`string`

The name of the target


