我希望能够创建一个字段中包含无效字符的类型。有了一张桌子,我可以这样做:
local Element = {
["$$typeof"] = 31337,
}对于Roblox类型,我不能这样做:
type Element = {
["$$typeof"]: number,
}如何才能在不使用any情况下强输入元素表中的字段
发布于 2021-10-06 22:40:49
您可以通过使用typeof运算符和--!strict杂注来完成此操作:
Element.lua
--!strict
local Element = {
["$$typeof"] = 0,
render = function(x, y) end :: (x: number, y: string?): ()
}
export type Element = typeof(Element)请注意:
typeof的返回能够保留高保真类型。::),具体取决于您的表赋值。https://stackoverflow.com/questions/69473417
复制相似问题