@loopback/docs
Version:
Documentation files rendered at [https://loopback.io](https://loopback.io)
39 lines (25 loc) • 1.21 kB
Markdown
---
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) > [@loopback/context](./context.md) > [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<[Injection](./context.injection.md)<!-- -->> | 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