types error in 0.58.3 when i use typescript
See original GitHub issueDo you want to request a feature or report a bug?
bug
What’s the current behavior?
i got error:
Argument of type 'Node[]' is not assignable to parameter of type 'SetStateAction<{ type: string; children: { text: string; }[]; }[]>'.
Type 'Node[]' is not assignable to type '{ type: string; children: { text: string; }[]; }[]'.
Type 'Node' is not assignable to type '{ type: string; children: { text: string; }[]; }'.
Property 'type' is missing in type 'Editor' but required in type '{ type: string; children: { text: string; }[]; }'. TS2345
Slate: 0.58.3
Browser: Chrome
OS: Mac
What’s the expected behavior?
no error
this is my code:
// code from https://docs.slatejs.org/walkthroughs/01-installing-slate
// Import React dependencies.
import React, { useEffect, useMemo, useState } from "react";
// Import the Slate editor factory.
import { createEditor } from 'slate'
// Import the Slate components and React plugin.
import { Slate, Editable, withReact } from 'slate-react'
export const Editor = () => {
const editor = useMemo(() => withReact(createEditor()), [])
// Add the initial value when setting up our state.
const [value, setValue] = useState([
{
type: 'paragraph',
children: [{ text: 'A line of text in a paragraph.' }],
},
])
return (
<Slate editor={editor} value={value} onChange={newValue => setValue(newValue)}>
<Editable />
</Slate>
)
}
this is my way , can fix the error:
change the code:
1.add import { Node } from 'slate';
2. change
const [value, setValue] = useState([
{
type: 'paragraph',
children: [{ text: 'A line of text in a paragraph.' }],
},
])
to
const [value, setValue] = useState<Node[]>([
{
type: 'paragraph',
children: [{ text: 'A line of text in a paragraph.' }],
},
])
its work!!!
the point is useState<Node[]>
Issue Analytics
- State:
- Created 3 years ago
- Reactions:16
- Comments:12 (1 by maintainers)
Top Results From Across the Web
Error: 'types' can only be used in a .ts file - Visual Studio Code ...
I'm using flow with vscode but had the same problem. I solved it with these steps: Install the extension Flow Language Support.
Read more >TypeScript errors and how to fix them
Common Errors Below you find a list of common TypeScript errors along with the buggy code and its fixed version.
Read more >Documentation - TypeScript 4.6
TypeScript now shows JavaScript syntax and binding errors in your file, such as using incorrect modifiers, duplicate declarations, and more. These will ...
Read more >Typescript errors when using @polkadot/api
As per the linked SO answer - metadata describes the chain, these types are only available at runtime, each chain is vastly different,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This is how I solved it.
The documentation doesn’t show this part, but you also have to add slate history and empty children. Basically, the whole sample app looks like this:
@jsoneaday and @connorjacobsen or anyone else. If you guys can share a sandbox I can take a look at it.