Have been beginning to strictly type check more and more, and I'm wondering, how do Type Parameters work?
How would you, say, define a function that make it's own function of which requires a type similar to how Signal+ does?
Below is my current experience with it; not even sure if it works ingame yet lol. but I know the type checking does
Feed me... INFORMATION...
--!strict
-- Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
-- Modules
local UtilitySignal = require(ReplicatedStorage.Modules.Utility.Signal)
-- Constants
-- Private Variables
-- Module
local Model = {}
type ChangedSignal = UtilitySignal.Signal<string, any>
export type ModelWrapper = {
Connections : {[BasePart] : RBXScriptConnection},
TransparencyNumbers : {[BasePart] : number},
Changed : ChangedSignal,
Model : Model,
TransparencyMultiplier : number,
Destroy : (ModelWrapper)->()
}
-- Initializing
function Model.new(templateModel : Model) : ModelWrapper
local self = {}
local proxy = {}
setmetatable(self, {
__index = function(t : ModelWrapper, index : any)
if proxy[index] then
return proxy[index]
end
return nil
end,
__newindex = function(t : ModelWrapper, index : any, v : any)
if proxy[index] ~= v then
proxy[index] = v
self.Changed:Fire(index, v)
end
end,
})
self.Changed = UtilitySignal() :: ChangedSignal
self.Model = templateModel:Clone()
self.Connections = {}
self.TransparencyNumbers = {}
for i,v in pairs(self.Model:GetDescendants()) do
if v:IsA("BasePart") then
local v :BasePart = v
local currentTransparency = v.Transparency or v:GetAttribute("Transparency")
self.TransparencyNumbers[v] = currentTransparency
self.Connections[v] = v:GetPropertyChangedSignal("Transparency"):Connect(function()
if self.TransparencyNumbers[v] and self.TransparencyNumbers[v] ~= v.Transparency then
self.TransparencyNumbers[v] = v.Transparency
end
end)
end
end
self.TransparencyMultiplier = 1
function self.Destroy()
for i,v in pairs(self.Connections) do
v:Disconnect()
end
if self.Model then
self.Model:Destroy()
end
end
self.Changed:Connect(function(index : string, value : any)
if table.find({"TransparencyNumbers", "TransparencyMultiplier"}, index) then
for i,v in pairs(self.TransparencyNumbers) do
i.Transparency = v * self.TransparencyMultiplier
end
end
end)
return self
end
-- Returning
return Model