Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The AnnotoriousContext doesn't use the AnnotoriousContextState type #421

Open
oleksandr-danylchenko opened this issue Jul 9, 2024 · 1 comment
Labels
v3.x Work on the next major release

Comments

@oleksandr-danylchenko
Copy link
Contributor

oleksandr-danylchenko commented Jul 9, 2024

Issue

The AnnotoriousContext is created using the auto-inferred type from the inline object:

export const AnnotoriousContext = createContext({
anno: undefined,
setAnno: undefined,
annotations: [],
selection: { selected: [] }
});

However, there's the AnnotoriousContextState lying around unused:
export interface AnnotoriousContextState {
anno: Annotator;
setAnno(anno: Annotator<Annotation, unknown>): void;
annotations: Annotation[];
selection: Selection;
}

That makes the props obtained from the useContext(AnnotoriousContext) have the any type:
image
Also, it allows unsafe accessing of possibly missing properties:
image

Suggested solution

The Annotorious may become a generic provider accepting the type for the specific Annotator sub-type, like the ImageAnnotator:

export interface ImageAnnotator<E extends unknown = ImageAnnotation> extends Annotator<ImageAnnotation, E> {
element: HTMLDivElement;
listDrawingTools(): string[];
registerDrawingTool(name: string, tool: typeof SvelteComponent, opts?: DrawingToolOpts): void;
registerShapeEditor(shapeType: ShapeType, editor: typeof SvelteComponent): void;
setDrawingTool(name: DrawingTool): void;
setDrawingEnabled(enabled: boolean): void;
setTheme(theme: Theme): void;
}

@rsimon
Copy link
Member

rsimon commented Jul 9, 2024

Oh - well, the intention was there ;-)

@rsimon rsimon added the v3.x Work on the next major release label Aug 8, 2024
@rsimon rsimon modified the milestone: 3.0.0 Aug 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
v3.x Work on the next major release
Projects
None yet
Development

No branches or pull requests

2 participants