How do devs find out about private members of native Obsidian classes?

I have recently started using Obsidian and decided to try writing some plugins. I started by examining existing community plugin files, such as nldates-obsidian by Argentina Ortega Sáinz. In it, I found that the devs are using private properties and methods of native Obsidian classes, like app.vault.getConfig() or EditorSuggest.suggestions, which I assume are used as shortcuts for otherwise public APIs.

Since they are neither covered by the docs nor the type declarations, how do devs find out about these private APIs?

There are many ways.

Personally I learned about app.vault.getConfig from Liam Cain’s website. (warning: some contents are outdated)

I encountered EditorSuggest.suggestions when reading the source code of Various Complements.

Playing around in the console

For example, in the dev console type this: app.vault.

Then you’ll see suggestions like this:

Some functions or classes are not directly accessible from console, but you can interact them in the console by, for example, writing

// in constructor of a subclass of EditorSuggest
(window as any).suggest = this

in your plugin.

Reading app.js etc

You can read app.js where the public & private API functions are defined from dev tools > Source. (but it’s a little bit hard to read because it’s minified)

obsidian-ex.d.ts

There is an unofficial type definition file called obsidian-ex.d.ts maintained by a community member. It’s not perfect but is really helpful.

Searching or asking in Discord

The plugin-dev channel is often helpful.

2 Likes

Thank you! I also realized some of those methods might stem from CodeMirror, so I will dive into those docs as well.

Yeah, learning CodeMirror is a little bit time-consuming but definitely fun. Enjoy!