I just accidentally found an answer to this, when I was just interested in another plugin and read its source code.
(Edit: While the following code may work, please find a better solution from my newer post further down this thread.)
In order to use
basePath, you need to instruct typescript not to yell about
basePath not being defined during compiling. Hence this has the line
//@ts-ignore. I don’t know why this supression is needed - I mean: why the property is not defined in the first place? If anyone else knows a better way to get the path, please let me know.
The code was copied from here: obsidian-open-with/main.ts at 84f0e25ba8e8355ff83b22f4050adde4cc6763ea · phibr0/obsidian-open-with · GitHub
Thanks @phibr0 and sorry for “stealing” a couple of lines of your code!