type MyType<A> = {
Func: (self: MyType<A>, A) -> (),
}
local function New<A>()
return {} :: MyType<A>
end
local value = New()
value:Func(1234)
using a type pack works fine
type MyType<A> = {
Func: (self: MyType<A>, A) -> (),
}
local function New<A>()
return {} :: MyType<A>
end
local value = New()
value:Func(1234)
using a type pack works fine
I believe in Luau, for generics to work you do have to pass a parameter typed with the generic.
Doing A... does cause a type error in strict mode
Passing a parameter where the generic is does work
Thanks for the report!
This is actually working as intended. When trying to figure out what A should be, Luau is only looking at the call to New(). Since there’s nothing there to help constrain A, it makes the most conservative guess it can: unknown.
We have an upcoming feature that will allow you to explicitly specify a type for the generic using the syntax local value = New<<number>>(1234), but it’s not quite ready yet.
That’s a shame
because this was a pattern i really enjoyed using on the old type solver
OLD TYPE SOLVER
and allowed me to do things like
OLD TYPE SOLVER
but now with the new type solver it no longer works
NEW TYPE SOLVER
i wish you guys would re consider this feature
it would also make types and type packs consistent its a little strange that it would work with
type packs but not a type
here is a more real world example
OLD TYPE SOLVER
session.Value is unknown