bustle / mobiledoc-kit

A toolkit for building WYSIWYG editors with Mobiledoc
https://bustle.github.io/mobiledoc-kit/demo/
MIT License
1.55k stars 156 forks source link

Unable to use in typescript project #785

Open ColinFrick opened 1 year ago

ColinFrick commented 1 year ago

I'm currently evaluating different wysiwyg editor projects (Slate, Quill, Tiptap) and I wanted to check mobile doc out.

Sadly I get following errors when trying to use it:

Error: node_modules/mobiledoc-kit/dist/mobiledoc.d.ts:406:9 - error TS2611: 'isBlank' is defined as a property in class '{ _tagName: string | null; tagName: string; isValidTagName(normalizedTagName: string): boolean; type: Type; isSection: boolean; isMarkerable: boolean; isNested: boolean; isListItem: boolean; ... 20 more ...; prev: any; }', but is overridden here in 'Markerable' as an accessor.

406     get isBlank(): boolean;
            ~~~~~~~

Error: node_modules/mobiledoc-kit/dist/mobiledoc.d.ts:437:9 - error TS2611: 'length' is defined as a property in class '{ _tagName: string | null; tagName: string; isValidTagName(normalizedTagName: string): boolean; type: Type; isSection: boolean; isMarkerable: boolean; isNested: boolean; isListItem: boolean; ... 20 more ...; prev: any; }', but is overridden here in 'Markerable' as an accessor.

437     get length(): number;
            ~~~~~~

Error: node_modules/mobiledoc-kit/dist/mobiledoc.d.ts:515:9 - error TS2611: 'post' is defined as a property in class 'Markerable', but is overridden here in 'ListItem' as an accessor.

515     get post(): Option<Post> | undefined;
            ~~~~

Error: node_modules/mobiledoc-kit/dist/mobiledoc.d.ts:562:9 - error TS2611: 'isBlank' is defined as a property in class '{ _tagName: string | null; tagName: string; isValidTagName(normalizedTagName: string): boolean; type: Type; isSection: boolean; isMarkerable: boolean; isNested: boolean; isListItem: boolean; ... 20 more ...; prev: any; } & Attributable', but is overridden here in 'ListSection' as an accessor.

562     get isBlank(): boolean;
            ~~~~~~~

I'm using typescript 4.8.3

gpoitch commented 1 year ago

You can add "skipLibCheck": true to tsconfig so you aren't type checking dependencies. We just released the type declarations so they may not be perfect yet. Will look into why these errors are occurring.

royemosby commented 1 year ago

Same issue and same output when trying import {DOMParser} from 'mobiledoc-kit'

vjonesmuth commented 1 year ago

I'm also seeing this issue in a typescript node application that is using ESM. I'm trying to do import { DOMParser, PostNodeBuilder, Renderer } from 'mobiledoc-kit';

But I get the following error:

(node:15254) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
...
export { DOMParser, Editor, MobiledocError as Error, ImageCard$2 as ImageCard, MOBILEDOC_VERSION$2 as MOBILEDOC_VERSION, Markup, Position, PostNodeBuilder, Range, MobiledocRenderer as Renderer, ui as UI };
^^^^^^

SyntaxError: Unexpected token 'export'

I believe we need to add "type": "module" to the package.json