@snap/camera-kit
Version:
Camera Kit Web
108 lines (65 loc) • 2.38 kB
Markdown
[CameraKit Web SDK - v0.22.0](../README.md) / [Exports](../modules.md) / TypedEventTarget
# Class: TypedEventTarget\<Events\>
This wrapper around EventTarget provides more descriptive type information. By using this class, calls to EventTarget
methods are correctly type checked to ensure only allowed event types are used, and that events and their type
strings are correctly associated.
For example, when calling TypedEventTarget::addEventListener, the event passed to the callback will have the correct
type corresponding to the type of event for which the listener has been added.
## Type parameters
| Name | Type |
| :------ | :------ |
| `Events` | extends [`TypedCustomEvent`](TypedCustomEvent.md) = [`TypedCustomEvent`](TypedCustomEvent.md) |
## Table of contents
### Constructors
- [constructor](TypedEventTarget.md#constructor)
### Methods
- [addEventListener](TypedEventTarget.md#addeventlistener)
- [dispatchEvent](TypedEventTarget.md#dispatchevent)
- [removeEventListener](TypedEventTarget.md#removeeventlistener)
## Constructors
### constructor
• **new TypedEventTarget**\<`Events`\>(): [`TypedEventTarget`](TypedEventTarget.md)\<`Events`\>
#### Type parameters
| Name | Type |
| :------ | :------ |
| `Events` | extends [`TypedCustomEvent`](TypedCustomEvent.md)\<`string`, `any`, `Events`\> = [`TypedCustomEvent`](TypedCustomEvent.md)\<`string`, `any`\> |
#### Returns
[`TypedEventTarget`](TypedEventTarget.md)\<`Events`\>
## Methods
### addEventListener
▸ **addEventListener**\<`K`\>(`type`, `callback`, `options?`): `void`
#### Type parameters
| Name | Type |
| :------ | :------ |
| `K` | extends `string` |
#### Parameters
| Name | Type |
| :------ | :------ |
| `type` | `K` |
| `callback` | `TypedEventListener`\<`EventOfType`\<`K`, `Events`\>\> |
| `options?` | `TypedEventListenerOptions` |
#### Returns
`void`
___
### dispatchEvent
▸ **dispatchEvent**(`event`): ``true``
#### Parameters
| Name | Type |
| :------ | :------ |
| `event` | `Events` |
#### Returns
``true``
___
### removeEventListener
▸ **removeEventListener**\<`K`\>(`type`, `callback`): `void`
#### Type parameters
| Name | Type |
| :------ | :------ |
| `K` | extends `string` |
#### Parameters
| Name | Type |
| :------ | :------ |
| `type` | `K` |
| `callback` | `TypedEventListener`\<`EventOfType`\<`K`, `Events`\>\> |
#### Returns
`void`