Skip to content

Commit

Permalink
Fix #813 Type error with getPlugin method
Browse files Browse the repository at this point in the history
  • Loading branch information
mistic100 committed Dec 28, 2022
1 parent 51425eb commit 91429ec
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions packages/core/src/Viewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import {
UpdatableViewerConfig,
ViewerConfig,
} from './model';
import type { AbstractPlugin } from './plugins/AbstractPlugin';
import type { AbstractPlugin, PluginConstructor } from './plugins/AbstractPlugin';
import { pluginInterop } from './plugins/AbstractPlugin';
import { PSVError } from './PSVError';
import { DataHelper } from './services/DataHelper';
Expand Down Expand Up @@ -222,8 +222,16 @@ export class Viewer extends TypedEventTarget<ViewerEvents> {

/**
* Returns the instance of a plugin if it exists
*/
getPlugin<T extends AbstractPlugin<any>>(pluginId: string | typeof AbstractPlugin): T {
* @example By plugin identifier
* ```js
* viewer.getPlugin('markers')
* ```
* @example By plugin class with TypeScript support
* ```ts
* viewer.getPlugin<MarkersPlugin>(MarkersPlugin)
* ```
*/
getPlugin<T extends AbstractPlugin<any>>(pluginId: string | PluginConstructor): T {
if (typeof pluginId === 'string') {
return this.plugins[pluginId] as T;
} else {
Expand Down

0 comments on commit 91429ec

Please sign in to comment.