refactor: use reduce generic type instead of type cast

Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
Philip Molares 2023-11-30 20:39:35 +01:00
parent e46b987201
commit 20f0a497ce
5 changed files with 29 additions and 33 deletions

View file

@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file)
* SPDX-FileCopyrightText: 2023 The HedgeDoc developers (see AUTHORS file)
*
* SPDX-License-Identifier: AGPL-3.0-only
*/
@ -34,7 +34,7 @@ export class YTextSyncViewPlugin implements PluginValue {
}
private calculateChanges(event: YTextEvent): ChangeSpec[] {
const [changes] = event.delta.reduce(
const [changes] = event.delta.reduce<[ChangeSpec[], number]>(
([changes, position], delta) => {
if (delta.insert !== undefined && typeof delta.insert === 'string') {
changes.push({ from: position, to: position, insert: delta.insert })
@ -48,7 +48,7 @@ export class YTextSyncViewPlugin implements PluginValue {
return [changes, position]
}
},
[[], 0] as [ChangeSpec[], number]
[[], 0]
)
return changes
}

View file

@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file)
* SPDX-FileCopyrightText: 2023 The HedgeDoc developers (see AUTHORS file)
*
* SPDX-License-Identifier: AGPL-3.0-only
*/
@ -43,10 +43,10 @@ export const convertClipboardTableToMarkdown = (pasteData: string): string => {
return ''
}
const tableRows = pasteData.split(/\r?\n/).filter((row) => row.trim() !== '')
const tableCells = tableRows.reduce((cellsInRow, row, index) => {
const tableCells = tableRows.reduce<string[][]>((cellsInRow, row, index) => {
cellsInRow[index] = row.split('\t')
return cellsInRow
}, [] as string[][])
}, [])
const arrayMaxRows = createNumberRangeArray(tableCells.length)
const arrayMaxColumns = createNumberRangeArray(Math.max(...tableCells.map((row) => row.length)))

View file

@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file)
* SPDX-FileCopyrightText: 2023 The HedgeDoc developers (see AUTHORS file)
*
* SPDX-License-Identifier: AGPL-3.0-only
*/
@ -12,20 +12,20 @@ interface EmojiEntry {
type ShortCodeMap = { [key: string]: string }
const shortCodeMap = (emojiData as unknown as EmojiEntry[]).reduce((reduceObject, emoji) => {
const shortCodeMap = (emojiData as unknown as EmojiEntry[]).reduce<ShortCodeMap>((reduceObject, emoji) => {
emoji.shortcodes.forEach((shortcode) => {
reduceObject[shortcode] = emoji.emoji
})
return reduceObject
}, {} as ShortCodeMap)
}, {})
const emojiSkinToneModifierMap = [1, 2, 3, 4, 5].reduce((reduceObject, modifierValue) => {
const emojiSkinToneModifierMap = [1, 2, 3, 4, 5].reduce<ShortCodeMap>((reduceObject, modifierValue) => {
const lightSkinCode = 127995
const codepoint = lightSkinCode + (modifierValue - 1)
const shortcode = `skin-tone-${modifierValue}`
reduceObject[shortcode] = `&#${codepoint};`
return reduceObject
}, {} as ShortCodeMap)
}, {})
export const combinedEmojiData = {
...shortCodeMap,

View file

@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2020 The HedgeDoc developers (see AUTHORS file)
* SPDX-FileCopyrightText: 2023 The HedgeDoc developers (see AUTHORS file)
*
* SPDX-License-Identifier: AGPL-3.0-only
*/
@ -17,8 +17,9 @@ export function convertInlineStyleToMap(
return {}
}
return inlineStyle.split(';').reduce(
(styleObject, stylePropertyValue) => {
return inlineStyle
.split(';')
.reduce<Record<string, string>>((styleObject, stylePropertyValue) => {
// extract the style property name and value
const [property, value] = stylePropertyValue
.split(/^([^:]+):/)
@ -44,7 +45,5 @@ export function convertInlineStyleToMap(
styleObject[replacedProperty] = value
return styleObject
},
{} as Record<string, string>
)
}, {})
}

View file

@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2020 The HedgeDoc developers (see AUTHORS file)
* SPDX-FileCopyrightText: 2023 The HedgeDoc developers (see AUTHORS file)
*
* SPDX-License-Identifier: AGPL-3.0-only
*/
@ -48,8 +48,7 @@ export function mapHtmlAttributesToReactElementAttributes(
!isEventHandlerAttribute(attribute) &&
isValidTagOrAttributeName(attribute)
)
.reduce(
(mappedAttributes, attribute) => {
.reduce<Record<string, string>>((mappedAttributes, attribute) => {
// lowercase the attribute name and find it in the react attribute map
const lowerCaseAttribute = attribute.toLowerCase()
@ -63,7 +62,5 @@ export function mapHtmlAttributesToReactElementAttributes(
)
return mappedAttributes
},
{} as Record<string, string>
)
}, {})
}