0

Is there any way how to make PhpStorm recognize what is a ckeditorInstance in this context?

const ckEditorElement = document.querySelector('.ck-editor__editable');

const ckEditorInstance = ckEditorElement?.ckeditorInstance;

Afterwards I try to access for example the model property on the instance and it just looks ugly in the code as every property is underlined.

In the dev tools console using querySelector() I can find the instance and it shows all of its available properties.

I see a bunch of ckeditor libraries in PhpStorm settings, but I am not sure if and how any of them are usable for what I need. Because just installing something wouldn't help in this case as I might need to typehint it somehow?

Example of what I mean, an issue I encountered before, but got a simple fix from How do I use WebStorm for Chrome Extension Development?

chrome unresolved variable

I resolved this by doing what is said in the posts accepted answer - which is to install a chrome type JS library in the settings. What I am doing is different obviously, but a similar issue, and maybe there is a fix to this?

4
  • Have you re-tested since correcting that? Has the behavior changed in any way as a result? It's not clear to me what specific problem you're trying to describe.
    – David
    Commented Jan 15 at 14:19
  • Yes, that was a typo. In my code I have that string as a constant. It does not change the problem which I have is that PHPStorm shows Unresolved variable ckeditorInstance. The code works, but then it underlines everything else I access on the instance, too, because it does not know what it is.
    – mrzalais
    Commented Jan 15 at 14:22
  • Have you tried using a JSDoc comment to explicitly provide the type of ckEditorElement to the IDE?
    – Oksana
    Commented Jan 16 at 12:08
  • Yes, I tried, but I am not sure what would be the correct approach to using JSDoc in this case. Defining the type as HTMLElement or Object doesn't help IDE know what properties does it contain. I added an example in my post for clarification.
    – mrzalais
    Commented Jan 16 at 12:30

0