---
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.

<b>Signature:</b>

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

## Parameters

|  Parameter | Type | Description |
|  --- | --- | --- |
|  injection | Readonly&lt;[Injection](./context.injection.md)<!-- -->&gt; | Injection information |
|  expectedType | Function | Expected type |
|  expectedTypeName | string | Name of the expected type to be used in the error |

<b>Returns:</b>

string

The name of the target


