Open NikitaIT opened 1 year ago
merge function has type PropsMerge which is defines as:
type PropsMerge = (prop: Partial<Node>, node: Partial<Node>) => object
As we see it expects objects but in setNodes
usage of merge doesn't match the type as we pass values key by key:
packages\slate\src\transforms-node\set-nodes.ts
if (merge) {
if (props[<keyof Node>k] != null)
newProperties[<keyof Node>k] = merge(
node[<keyof Node>k],
props[<keyof Node>k]
)
}
Thus i guess PropsMerge
type should expect key and appropriate values of descendant, similar to this:
type PropsMerge = <TValue extends Descendant[keyof Descendant]>(key: keyof Descendant, prop: TValue, node: TValue) => TValue
I have no idea how to implement this to get it working with typescript inferring
https://github.com/ianstormtaylor/slate/blob/c8236ee112969fcab70ff4f159e1e4a18084ca6b/packages/slate/src/interfaces/transforms/node.ts#L85-L96
If we have only one key in
props
then real type ismerge?: (prop: T["key"], node: T["key"]) => T["key"]
Example:
Example2: