---
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 markdown="1">

injection


</td><td markdown="1">

Readonly&lt;[Injection](./context.injection.md)<!-- -->&gt;


</td><td markdown="1">

Injection information


</td></tr>
<tr><td markdown="1">

expectedType


</td><td markdown="1">

Function


</td><td markdown="1">

Expected type


</td></tr>
<tr><td markdown="1">

expectedTypeName


</td><td markdown="1">

string


</td><td markdown="1">

_(Optional)_ Name of the expected type to be used in the error


</td></tr>
</tbody></table>

**Returns:**

string

The name of the target


