Definitelytyped: [Slate-React] node is not assignable to DocumentJSON

Created on 20 Jan 2019  路  6Comments  路  Source: DefinitelyTyped/DefinitelyTyped

@andykent, @majelbstoat @JanLoebel @YangusKhan @kalley @Kornil @isubasti @sgreav

I just copied initialValue from the documentation and I get a type error.

image

image

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.',
},
],

All 6 comments

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."
          }
        ]
Was this page helpful?
0 / 5 - 0 ratings

Related issues

lilling picture lilling  路  3Comments

Zzzen picture Zzzen  路  3Comments

demisx picture demisx  路  3Comments

alisabzevari picture alisabzevari  路  3Comments

JudeAlquiza picture JudeAlquiza  路  3Comments