chore: replace explicit any with concrete types in shared (#12201)

* chore: replace explicit any with concrete types in shared

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* chore: address review feedback

- naturalSort: guard non-string field values instead of asserting string
- ProsemirrorHelper: type stored mark attrs as Partial<CommentMark>
- env: revert to Record<string, any>; safer typing requires fixing many consumers

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Tom Moor
2026-04-28 19:51:51 -04:00
committed by GitHub
parent 5610df5a26
commit cd9e79b1f1
6 changed files with 24 additions and 13 deletions
+3 -2
View File
@@ -17,6 +17,7 @@ import {
mergeCells,
splitCell,
TableMap,
type TableRect,
} from "prosemirror-tables";
import { ProsemirrorHelper } from "../../utils/ProsemirrorHelper";
import { CSVHelper } from "../../utils/csv";
@@ -103,7 +104,7 @@ export function createTableInner(
const cells: Node[] = [];
const rows: Node[] = [];
const createCell = (cellType: NodeType, attrs: Record<string, any> | null) =>
const createCell = (cellType: NodeType, attrs: Attrs | null) =>
cellContent
? cellType.createChecked(attrs, cellContent)
: cellType.createAndFill(attrs);
@@ -916,7 +917,7 @@ export function splitCellAndCollapse(): Command {
*/
function addRowWithAlignment(
tr: Transaction,
rect: any,
rect: TableRect,
index: number,
copyFromRow: number | undefined,
state: EditorState
+4 -2
View File
@@ -37,7 +37,7 @@ type Attrs = {
} & Record<string, JSONValue>;
const getAttributesFromNode = (node: Node): Attrs => {
const spec = node.type.spec.toDOM?.(node) as any as Record<
const spec = node.type.spec.toDOM?.(node) as unknown as Record<
string,
JSONValue
>[];
@@ -45,7 +45,9 @@ const getAttributesFromNode = (node: Node): Attrs => {
return {
className: className as Attrs["className"],
unfurl: unfurl ? (JSON.parse(unfurl as any) as Attrs["unfurl"]) : undefined,
unfurl: unfurl
? (JSON.parse(unfurl as string) as Attrs["unfurl"])
: undefined,
...attrs,
};
};
+2 -2
View File
@@ -8,7 +8,7 @@ import type { Primitive } from "utility-types";
import type { Editor } from "~/editor";
import type Mark from "../marks/Mark";
import type Node from "../nodes/Node";
import type { CommandFactory } from "./Extension";
import type { CommandFactory, WidgetProps } from "./Extension";
import type Extension from "./Extension";
import makeRules from "./markdown/rules";
import { MarkdownSerializer } from "./markdown/serializer";
@@ -67,7 +67,7 @@ export default class ExtensionManager {
.reduce(
(memo, node: Node) => ({
...memo,
[node.name]: observer(node.widget as any),
[node.name]: observer(node.widget as React.FC<WidgetProps>),
}),
{}
);
+2 -1
View File
@@ -1,4 +1,5 @@
import copy from "copy-to-clipboard";
import type Token from "markdown-it/lib/token.mjs";
import { textblockTypeInputRule } from "prosemirror-inputrules";
import type {
Node as ProsemirrorNode,
@@ -80,7 +81,7 @@ export default class Heading extends Node {
parseMarkdown() {
return {
block: "heading",
getAttrs: (token: Record<string, any>) => ({
getAttrs: (token: Token) => ({
level: +token.tag.slice(1),
}),
};
+9 -2
View File
@@ -219,7 +219,12 @@ export class ProsemirrorHelper {
}
});
(node.attrs.marks ?? []).forEach((mark: any) => {
(
(node.attrs.marks ?? []) as {
type: string;
attrs: Partial<CommentMark>;
}[]
).forEach((mark) => {
if (mark.type === "comment") {
comments.push({
...mark.attrs,
@@ -271,7 +276,9 @@ export class ProsemirrorHelper {
const anchors: NodeAnchor[] = [];
doc.descendants((node, pos) => {
if (Array.isArray(node.attrs?.marks)) {
node.attrs.marks.forEach((mark: any) => {
(
node.attrs.marks as { type?: string; attrs?: { id?: string } }[]
).forEach((mark) => {
if (mark?.type === "comment" && mark?.attrs?.id) {
anchors.push({
pos,
+4 -4
View File
@@ -14,18 +14,18 @@ const stripEmojis = (value: string) => value.replace(regex, "");
const cleanValue = (value: string) => stripEmojis(deburr(value));
function getSortByField<T extends Record<string, any>>(
function getSortByField<T extends object>(
item: T,
keyOrCallback: string | ((item: T) => string)
) {
const field =
typeof keyOrCallback === "string"
? item[keyOrCallback]
? (item as Record<string, unknown>)[keyOrCallback]
: keyOrCallback(item);
return cleanValue(field);
return cleanValue(typeof field === "string" ? field : "");
}
function naturalSortBy<T extends Record<string, any>>(
function naturalSortBy<T extends object>(
items: T[],
key: string | ((item: T) => string),
sortOptions?: NaturalSortOptions