@andykent, @majelbstoat @JanLoebel @YangusKhan @kalley @Kornil @isubasti @sgreav
@types/xxxx package and had problems.I just copied initialValue from the documentation and I get a type error.


just add 'object' property to 'leaves' property.
original code was
leaves: [
{
text: 'A line of text in a paragraph.',
},
],
current code is
leaves: [
{
object: 'leaf', // add this line!!!!!
text: 'A line of text in a paragraph.',
},
],
Your error happens as the typescript version rising up.(not sure)
Take care ? mark at the declaration of properties
adding object: 'leaf', as suggested by @scarletks1214 does solve the problem.
Is there a problem in @types/slate or should the documentation be fixed?
also faced the same error, it's because object: "leaf" is required in TextJSON, but it was missing in the example
can be suppressed by adding object: "leaf" back, not sure if it's problem of @types/slate or the doc though
const initialValue = Value.fromJSON({
document: {
nodes: [
{
object: "block",
type: "paragraph",
nodes: [
{
object: "text",
leaves: [
{
object: "leaf", // <----- add this line
text: "A line of text in a paragraph."
}
]
}
]
}
]
}
});
For now there leaves is deprecated, but type definition isn't updated.
So you need to use old way or new with ts-ignore:
nodes: [
{
object: "text",
// @ts-ignore
text: "A line of text in a paragraph."
}
]
Most helpful comment
original code was
leaves: [
{
text: 'A line of text in a paragraph.',
},
],
current code is
leaves: [
{
object: 'leaf', // add this line!!!!!
text: 'A line of text in a paragraph.',
},
],