Closed
Description
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.
local M = {}
---@class Config
---@field foo string
---@field bar number
M.options = {}
---@type Config
default = {
foo = "foo",
bar = 1,
}
---@class Config.P
---@field foo? string
---@field bar? number
---@param opts Config.P
local function setup(opts)
M.options = tbl_merge(default, M.options, opts)
-- ...
end
Metadata
Metadata
Assignees
Labels
No labels