mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-01-18 05:59:13 +01: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:
parent
9e8d5e2b9b
commit
e0f41514a1
5
.changeset/late-spoons-cheer.md
Normal file
5
.changeset/late-spoons-cheer.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
'slate': patch
|
||||
---
|
||||
|
||||
Improve typescript type of `props` argument of `Transforms.setNodes()`
|
@ -67,7 +67,7 @@ export interface NodeTransforms {
|
||||
) => void
|
||||
setNodes: <T extends Node>(
|
||||
editor: Editor,
|
||||
props: Partial<Node>,
|
||||
props: Partial<T>,
|
||||
options?: {
|
||||
at?: Location
|
||||
match?: NodeMatch<T>
|
||||
|
@ -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: [] }
|
||||
|
Loading…
x
Reference in New Issue
Block a user