requireSource()function
requireSource(type: Class<T>, data: unknown, caller: AnyCaller = requireSource): T
| Param | Type | |
|---|---|---|
type | Class<T> | The class to search for an instance of. required |
data | unknown | The object to start searching from. required |
caller | AnyCaller | Function to attribute a thrown error to (defaults to requireSource). Defaults to requireSource |
| Return | |
|---|---|
T | The first matching source instance. |
| Throws | |
|---|---|
RequiredError | If no source object is an instance of type. |
Recurse through Sourceable objects and return the first one that is an instance of type, or throw RequiredError if no source object matches.
- Like
getSource(), but throws instead of returningundefinedwhen no match is found.
Examples
requireSource(CacheProvider, provider) // CacheProvider instance