Closed
Description
Bug Report
π Search Terms
Generics, infer, derived, unused, doesn't work
β― Playground Link
Playground link with relevant code
π» Code
type A<T, Y, Z> = () => true; // this does not work
// type A<T, Y, Z> = () => T; // this works
type InferT<I> = I extends A<infer T, any, any> ? T : never;
// typeof directInfer is "true"
let directInfer: InferT<A<true, null, null>>; // this works either way
type B<T> = A<T, null, null>;
const test: B<true> = () => true;
// typeof indirectInfer is "uknown"
// should be of type "true", and it works if you uncomment the line above
let indirectInfer: InferT<typeof test>;
π Actual behavior
-
If you make a generic
A
which does not necessarily use all of its arguments, then instantiate a variable of that type, you can still useinfer
to pull out every generic argument from it. -
If you then make a new generic
B
which is a version ofA
with some fields pre-filled, then use the same inference function as forA
, it will no longer work on generic arguments which are not used inA
. -
If you then change
A
to use all of its generic arguments, inferring fromB
will now work.
π Expected behavior
It shouldn't matter whether or not the base generic A
uses a generic field. If it can be inferred one way, it should be able to be inferred either way.
Metadata
Metadata
Assignees
Labels
No labels