You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want a generics equivalent to Partial<T> in TypeScript.
When creating some extension in lua, the user should write only the parts that they want to change from the default settings in order to configure it. Internally, however, the user settings are merged with the default settings to create a configuration table with no missing field. In this case, I am not happy to have to define these two classes separately, because it can cause bugs due to synchronization errors.
It seems currently the diagnostic for missing fields does not take into account inheritance so I end up doing what you do here but instead of redefining every field I use ---@class Config.P: Config. The convention implies everything is optional (the hover/intellisense doesn't) and you do not receive a warning on "missing" fields.
This also means that abusing this bug and enabling something like a generic inheritance ---@class Optional<T>: T would be great, this is currently not possible though.
I think following recent updates in LuaLS we could end up with a suffix for the @param fields to disable such warnings. Like: ---@param(partial) opts Config
Having something to mark a type's (or class's) fields as optional is sorely needed. Otherwise, you have to go and recreate/redefine it several times, which is just not feasible especially if you have more than a few fields. My use-case is similar to yours.
It seems currently the diagnostic for missing fields does not take into account inheritance
I came across that recently too. Definitely a bug imo.
I want a generics equivalent to
Partial<T>
in TypeScript.When creating some extension in lua, the user should write only the parts that they want to change from the default settings in order to configure it. Internally, however, the user settings are merged with the default settings to create a configuration table with no missing field. In this case, I am not happy to have to define these two classes separately, because it can cause bugs due to synchronization errors.
The text was updated successfully, but these errors were encountered: