League-of-Foundry-Developers / foundry-vtt-types

Unofficial type declarations for the Foundry Virtual Tabletop API
MIT License
109 stars 49 forks source link

Audit all usages of common footgun types like `object` #2595

Open LukeAbby opened 1 week ago

LukeAbby commented 1 week ago

object is the wrong type in 99% of cases because it includes all functions and all arrays. It has some limited usage in complex scenarios, mostly to prevent an index signature but that only matters when the base constraint is used or in other similarly niche scenarios.

Even when any object, any array, or any function is truly meant it's more self documenting to say Record<string, unknown> | Record<number, unknown> | (...args: any[]) => any. If this is a common situation then helper types could shorten it.

LukeAbby commented 1 week ago

Similar footgun types include, but are not limited to:

Therefore the best constraint to use for most objects would be { readonly [K: string]: T } unless mutability is actively desired.