requireSource()function

requireSource(type: Class<T>, data: unknown, caller: AnyCaller = requireSource): T
ParamType
typeClass<T>
The class to search for an instance of. required
dataunknown
The object to start searching from. required
callerAnyCaller
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 returning undefined when no match is found.

Examples

requireSource(CacheProvider, provider) // CacheProvider instance