Skip to content

Commit

Permalink
Added styleClass processing with expect-error
Browse files Browse the repository at this point in the history
  • Loading branch information
oleksandr-danylchenko committed Nov 4, 2024
1 parent c899610 commit 2110c58
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions packages/text-annotator/src/model/w3c/W3CTextFormatAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ const parseW3CTextTargets = (annotation: W3CTextAnnotation) => {
updated: modified ? new Date(modified) : undefined,
annotation: annotationId,
selector: [],
styleClass: w3cTargets[0].styleClass
// @ts-expect-error: `styleClass` is not part of the core `TextAnnotationTarget` type
styleClass: 'styleClass' in w3cTargets[0] ? w3cTargets[0].styleClass : undefined
};

for (const w3cTarget of w3cTargets) {
Expand All @@ -68,12 +69,14 @@ const parseW3CTextTargets = (annotation: W3CTextAnnotation) => {
}, {});

if (isTextSelector(selector)) {
parsed.selector.push({
...selector,
id: w3cTarget.id,
// @ts-ignore
scope: w3cTarget.scope
});
parsed.selector.push(
{
...selector,
id: w3cTarget.id,
// @ts-expect-error: `scope` is not part of the core `TextSelector` type
scope: w3cTarget.scope
}
);
} else {
const missingTypes = [
!selector.start ? 'TextPositionSelector' : undefined,
Expand Down Expand Up @@ -131,7 +134,7 @@ export const serializeW3CTextAnnotation = (
...targetRest
} = target;

const w3cTargets = selector.map((s) => {
const w3cTargets = selector.map((s): W3CTextAnnotationTarget => {
const { id, quote, start, end, range } = s;

const { prefix, suffix } = getQuoteContext(range, container);
Expand All @@ -150,10 +153,11 @@ export const serializeW3CTextAnnotation = (
return {
...targetRest,
id,
// @ts-expect-error: `scope` is not part of the core `TextAnnotationTarget` type
scope: 'scope' in s ? s.scope : undefined,
source,
selector: w3cSelectors
} as W3CTextAnnotationTarget;
};
});


Expand Down

0 comments on commit 2110c58

Please sign in to comment.