ianstormtaylor / slate

A completely customizable framework for building rich text editors. (Currently in beta.)
http://slatejs.org
MIT License
29.29k stars 3.21k forks source link

Docs: Typescript examples are faulty or missing #4395

Open schlenger opened 2 years ago

schlenger commented 2 years ago

Problem I tried to setup a sample project by reading the docs and stumbled upon some missing dependencies and wrongly formatted code which is hard to fix if someone tries to implement the initial setup as a beginner.

Solution The sections in https://docs.slatejs.org/walkthroughs/01-installing-slate as well as https://docs.slatejs.org/concepts/12-typescript need formatting updates as well as a check if things work if you stick to the documentation.

Context I can take care of this, if it is helpful.

schlenger commented 2 years ago

Sidenote: When implementing https://docs.slatejs.org/walkthroughs/05-executing-commands in TS, there is an issue, that bold is used for spans in prior and in this example for the complete blocks

ghost commented 2 years ago

I found the docs hard to follow too when using TS. The best solution would be to split every page into two separate JS and TS sections.

Andrewnt219 commented 2 years ago

@ilovecommits In the 01-installing-slate, the TypeScript code for setting up the component has a compilation error. CustomElement should be an array.

// Correct version
const App = () => {
  const initialValue: CustomElement[] = []
  //...
}

image

ghost commented 2 years ago

@ilovecommits In the 01-installing-slate, the TypeScript code for setting up the component has a compilation error. CustomElement should be an array.

// Correct version
const App = () => {
  const initialValue: CustomElement[] = []
  //...
}

image

Not sure why you tagged me, but just submit a PR.

TrySpace commented 2 years ago

Same, getting:

Subsequent property declarations must have the same type.  Property 'Element' must be of type 'CustomElement', but here has type 'CustomElement'.

When trying the first example

BrentFarese commented 1 year ago

Sidenote: When implementing https://docs.slatejs.org/walkthroughs/05-executing-commands in TS, there is an issue, that bold is used for spans in prior and in this example for the complete blocks

@TrySpace were you able to resolve this? I am getting a similar error in my codebase.

maral commented 3 months ago

In 2024 I came here to complain about this, once again. It would be really nice to be able to understand which types I should use for all the different use cases, instead of putting any or @ts-ignore everywhere so the code even compiles...