obsidianmd/obsidian-api

Replace `any` with more specific types

mProjectsCode opened this issue · 1 comments

There are some instances where things in the API are typed as any. E.g. the new onExternalSettingsChange which has its return type typed as any, which according to liam is so that the function can easily be made async.

The same effect can be achieved with something like void | Promise<void> or a generic helper type e.g.

type MaybePromise<T> = T | Promise<T>;

That way the function can be typed as

onExternalSettingsChange?(): MaybePromise<void>;

Which would make it clear that the function can be async and returns nothing.

This is an unnecessary move that would end up restricting the type and complicating the type compiler. Using any means "our API does not care what you return, whether it's void, number, Promise<something>, it doesn't matter.

Your suggestion makes it impossible to return non-void types, which is not something we care about.