fix: make eventUtils throw if event type not registered (#6381)

* chore: update lint rules

* fix: have eventUtils.get throw if event isn't found

* chore: remove nonnull assertion from eventUtils.get and format
This commit is contained in:
Maribeth Bottorff
2022-08-24 13:41:32 -07:00
committed by GitHub
parent 980fe138e7
commit 60bc01acc8
29 changed files with 98 additions and 94 deletions

View File

@@ -507,12 +507,16 @@ export function fromJson(
* Gets the class for a specific event type from the registry.
*
* @param eventType The type of the event to get.
* @returns The event class with the given type or null if none exists.
* @returns The event class with the given type.
* @alias Blockly.Events.utils.get
*/
export function get(eventType: string):
(new (...p1: AnyDuringMigration[]) => Abstract)|null {
return registry.getClass(registry.Type.EVENT, eventType);
(new (...p1: AnyDuringMigration[]) => Abstract) {
const event = registry.getClass(registry.Type.EVENT, eventType);
if (!event) {
throw new Error(`Event type ${eventType} not found in registry.`);
}
return event;
}
/**