mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-31 10:51:44 +02:00
Improve props
argument type in Transforms.setNodes()
(#4638)
* Fix `setNodes()` props argument type Because Typescript can know which type of nodes we are modifying thanks to the `T` inferred from `match` function, it can also properly narrow down the `props` argument type. * Fix TS errors in examples * Add a changeset
This commit is contained in:
@@ -73,7 +73,9 @@ const VideoElement = ({ attributes, children, element }) => {
|
||||
const newProperties: Partial<SlateElement> = {
|
||||
url: val,
|
||||
}
|
||||
Transforms.setNodes(editor, newProperties, { at: path })
|
||||
Transforms.setNodes<SlateElement>(editor, newProperties, {
|
||||
at: path,
|
||||
})
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
|
@@ -37,7 +37,9 @@ const withLayout = editor => {
|
||||
const enforceType = type => {
|
||||
if (SlateElement.isElement(child) && child.type !== type) {
|
||||
const newProperties: Partial<SlateElement> = { type }
|
||||
Transforms.setNodes(editor, newProperties, { at: childPath })
|
||||
Transforms.setNodes<SlateElement>(editor, newProperties, {
|
||||
at: childPath,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -67,7 +67,7 @@ const withShortcuts = editor => {
|
||||
const newProperties: Partial<SlateElement> = {
|
||||
type,
|
||||
}
|
||||
Transforms.setNodes(editor, newProperties, {
|
||||
Transforms.setNodes<SlateElement>(editor, newProperties, {
|
||||
match: n => Editor.isBlock(editor, n),
|
||||
})
|
||||
|
||||
|
@@ -74,7 +74,7 @@ const toggleBlock = (editor, format) => {
|
||||
const newProperties: Partial<SlateElement> = {
|
||||
type: isActive ? 'paragraph' : isList ? 'list-item' : format,
|
||||
}
|
||||
Transforms.setNodes(editor, newProperties)
|
||||
Transforms.setNodes<SlateElement>(editor, newProperties)
|
||||
|
||||
if (!isActive && isList) {
|
||||
const block = { type: format, children: [] }
|
||||
|
Reference in New Issue
Block a user