How are you getting typescript examples to compile #5787
Unanswered
mikeycoxon
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Right now, I'm looking at: https://github.com/ianstormtaylor/slate/blob/main/site/examples/ts/paste-html.tsx
in association with:
https://github.com/ianstormtaylor/slate/blob/main/site/examples/ts/richtext.tsx
https://github.com/ianstormtaylor/slate/blob/main/site/examples/ts/custom-types.d.ts
and I had numerous issues with compiling:
For example I had to change in paste-html.tsx
line 14 from:
const ELEMENT_TAGS = {
to:
const ELEMENT_TAGS: any = {
line 15 from:
A: el => ({ type: 'link', url: el.getAttribute('href') }),
to:
A: (el: HTMLElement) => ({ type: 'link', url: el.getAttribute('href') }) as CustomElement,
otherwise I would have my typescript complaining about type mismatches.
I looked at your various tsconfig.json files and I can see that they are pretty relaxed. Is that how?
If that's the case, then can I suggest that you tighten them up, so that your tsx examples are more useful?
ADDENDUM:
and nowhere would this be more useful than on line 48 in: https://github.com/ianstormtaylor/slate/blob/main/site/examples/ts/paste-html.tsx
return '\n'
the string '\n' is neither an array of Descendant, or even a singular Descendant, and Slate requires that the result of the serialisation be at least an array of Node[], which needs to include EmptyText at the very least.
So under the circumstances, I can change line 48 to read:
return {text: '\n'} as EmptyText
but that changes the structure
So how do I get the serializer to work under a more realistic typescript environment?
Beta Was this translation helpful? Give feedback.
All reactions