annotorious icon indicating copy to clipboard operation
annotorious copied to clipboard

The `AnnotoriousContext` doesn't use the `AnnotoriousContextState` type

Open oleksandr-danylchenko opened this issue 1 year ago • 1 comments

Issue

The AnnotoriousContext is created using the auto-inferred type from the inline object: https://github.com/annotorious/annotorious/blob/9188ea1d73911209dcd367734e7f45f5382950e3/packages/annotorious-react/src/Annotorious.tsx#L26-L36 However, there's the AnnotoriousContextState lying around unused: https://github.com/annotorious/annotorious/blob/9188ea1d73911209dcd367734e7f45f5382950e3/packages/annotorious-react/src/Annotorious.tsx#L14-L24

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: https://github.com/annotorious/annotorious/blob/9188ea1d73911209dcd367734e7f45f5382950e3/packages/annotorious/src/Annotorious.ts#L20-L36

oleksandr-danylchenko avatar Jul 09 '24 13:07 oleksandr-danylchenko

Oh - well, the intention was there ;-)

rsimon avatar Jul 09 '24 13:07 rsimon