[New solver] Generic detection not working

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

3 Likes

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

1 Like

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 :sob: 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


this currently only works on the old type solver on the new type solver session.Value is unknown