You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
typeA<T,Y,Z>=()=>true;// this does not work// type A<T, Y, Z> = () => T; // this workstypeInferT<I>=IextendsA<infer T,any,any> ? T : never;// typeof directInfer is "true"letdirectInfer: InferT<A<true,null,null>>;// this works either waytypeB<T>=A<T,null,null>;consttest: B<true>=()=>true;// typeof indirectInfer is "uknown"// should be of type "true", and it works if you uncomment the line aboveletindirectInfer: InferT<typeoftest>;
π 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 use infer to pull out every generic argument from it.
If you then make a new generic B which is a version of A with some fields pre-filled, then use the same inference function as for A, it will no longer work on generic arguments which are not used in A.
If you then change A to use all of its generic arguments, inferring from B 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.
The text was updated successfully, but these errors were encountered:
This is working as intended; see this FAQ entry. TypeScript's type system is structural and not nominal; if a type doesn't depend structurally on T, then in principle you can't infer T from it. (In practice, sometimes the compiler can do this, but it really shouldn't be relied upon).
Bug Report
π Search Terms
Generics, infer, derived, unused, doesn't work
β― Playground Link
Playground link with relevant code
π» Code
π 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.The text was updated successfully, but these errors were encountered: