0

I use tinymce in my project and installed @types/tinymce. However when calling tinymce.init() and passing the Settings object some of the properties are missing in @types/tinymce's index.d.ts and I get an error:

Calling code:

tinymce.init({
  selector: "#editor",
  height: 400,
  plugins: "paste",
  element_format: "html",
  paste_block_drop: true,
  [...]
}

Error message:

Argument of type '{ selector: string; height: number; menubar: string; toolbar: string; plugins: string; element_format: string; paste_data_images: true; paste_block_drop: boolean; paste_enable_default_filters: boolean; paste_remove_styles: boolean; paste_retain_style_properties: string; setup: (editor: Editor) => void; }' is not assignable to parameter of type 'Settings'.
  Object literal may only specify known properties, and 'paste_block_drop' does not exist in type 'Settings'.

The definition in index.d.ts looks like this:

export interface Settings {
  base_url?: string;
  table_toolbar?: string;
  [...]
}

I searched and read several StackOverflow answers and read Typescript docs and tried to create a file tinymce-extensions.d.ts with this content:

export interface Settings {
  paste_block_drop?: boolean;
}

However it does not work, I still get above error message. What am I doing wrong?

Oliver Kötter
  • 1,006
  • 11
  • 29
  • Does this helps? https://stackoverflow.com/questions/46678663/add-custom-typings-file-in-a-javascript-vscode-project/50990886#50990886 – Drag13 Jul 24 '20 at 06:46
  • Make sure the d.ts file included in type definitions in your ts.config. – Eldar Jul 24 '20 at 06:47
  • @Drag13 The solution cannot be to add or alter files within node_modules. Then I could alter index.d.ts directly. – Oliver Kötter Jul 24 '20 at 07:45
  • @Eldar I don't think this is necessary? I extend another interface in this project and it simply works without any mods in tsconfig.json. I tried to add my d.ts file to tsconfig.json but that did not help. – Oliver Kötter Jul 24 '20 at 07:46

1 Answers1

1

I tried several approaches and they are not working. I am not sure, but I have a feeling that something is broken.

So, if you can't commit this lib and still want to have types, you can use this simple, but quite ugly way:

tinymce.init({
    selector: "#editor",
    height: 400,
    plugins: "paste",
    element_format: "html",
    paste_block_drop: true,
} as Settings)
Drag13
  • 5,859
  • 1
  • 18
  • 42