Can't compile the quickstart on typescript
See original GitHub issueDescription I’m following the quickstart guide with typescript and it will not compile.
Here’s my code, as per the quickstart:
import React, { useEffect, useMemo, useState} from 'react';
import { render } from 'react-dom';
import { BaseEditor, createEditor } from 'slate';
import { Slate, ReactEditor, Editable, withReact } from 'slate-react';
type CustomElement = { type: 'paragraph'; children: CustomText[] }
type CustomText = { text: string }
declare module 'slate' {
interface CustomTypes {
Editor: BaseEditor & ReactEditor
Element: CustomElement
Text: CustomText
}
}
const App = () => {
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>
)
}
render(<App />, document.getElementById('root'));
Here are the errors I get:
TS2322: Type '{ type: string; children: { text: string; }[]; }[]' is not assignable to type 'Descendant[]'.
Type '{ type: string; children: { text: string; }[]; }' is not assignable to type 'Descendant'.
Type '{ type: string; children: { text: string; }[]; }' is not assignable to type 'CustomElement'.
Types of property 'type' are incompatible.
Type 'string' is not assignable to type '"paragraph"'.
TS2345: Argument of type 'Descendant[]' is not assignable to parameter of type 'SetStateAction<{ type: string; children: { text: string; }[]; }[]>'.
Type 'Descendant[]' is not assignable to type '{ type: string; children: { text: string; }[]; }[]'.
Type 'Descendant' is not assignable to type '{ type: string; children: { text: string; }[]; }'.
Type 'CustomText' is missing the following properties from type '{ type: string; children: { text: string; }[]; }': type, children
Here is my tsconfig:
{
"compilerOptions": {
"module": "commonjs",
"noImplicitAny": true,
"removeComments": true,
"preserveConstEnums": true,
"sourceMap": true,
"esModuleInterop": true,
"jsx": "react"
},
"include": ["src/ts/*"],
}
Environment
- Slate Version: 0.63.0
- Operating System: macOS
- TypeScript Version: 4.2.4
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:9 (2 by maintainers)
Top Results From Across the Web
TypeScript Compiling with Visual Studio Code
To generate source maps for your TypeScript files, compile with the --sourcemap option or set the sourceMap property in the tsconfig. json file...
Read more >Common TypeScript module problems and how to solve them
Solution 1: Locate the correct directory ; "compilerOptions": ; "baseUrl": ; ".", ; "paths": ; "express": ...
Read more >Typescript project compile errors - node.js - Stack Overflow
When i try to run compile , but on compiling I see the errors that it cannot import express and body parser. But...
Read more >Getting Started with Executing TypeScript files in ts-node
6. Run the following command to compile your TypeScript code ( main.ts ) without checking for errors ( -T ). Compiling your TypeScript...
Read more >Getting Started with Typescript - Run & Compile with Webpack
7 of 11 - Getting Started with Typescript - Run & Compile with WebpackLearn how to setup Node.js, ... Your browser can't play...
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
solved with dirty trick: type casting,
createEditor() as ReactEditor
What to do with this line?
const editor = useMemo(() => withHistory(withReact(createEditor())), []);
it complains:Argument of type 'BaseEditor' is not assignable to parameter of type 'ReactEditor'. Type 'BaseEditor' is missing the following properties from type 'ReactEditor': insertData, setFragmentData, hasRange