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
{{ message }}
Repository navigation
Function involving FlatArray is transformed in declaration in an incompatible type.Β #49572
// This function's type is changed on declarationexportconstfun=(subFun: <Collection,FieldextendskeyofCollection>()=>FlatArray<Collection[Field],0>[])=>{};// This argument should match the type of argument used by funconstsubFunExample=<Collection,FieldextendskeyofCollection>()
: FlatArray<Collection[Field],0>[]=>[];// Typescript does not throw any error therefun(subFunExample);// This is the type found for fun in the declaration file. It should be equivalent to the type for fun.constfun_declaration: (subFun: <Collection,FieldextendskeyofCollection>()=>(Collection[Field]extends infer T ? TextendsCollection[Field] ? Textendsreadonlyunknown[] ? unknown : T : never : never)[])=>void=(_)=>{};// Typescript throws an error there.fun_declaration(subFunExample);
π Actual behavior
When the declaration is created, the type of fun is transformed to (subFun: <Collection, Field extends keyof Collection>() => (Collection[Field] extends infer T ? T extends Collection[Field] ? T extends readonly unknown[] ? unknown : T : never : never)[]) => void;.
This declaration type does not recognize arguments that were matched by the original type.
π Expected behavior
No error. Declaration type should be equivalent to the original type: if typescript does not raise an error with the original type, it should raise an error for the declaration type.
I've tried to find a simpler type exhibiting this behavior, but didn't find any.
Hm, so our old emit was compatible, true, but it didn't execute over unions correctly. The new emit was introduced to distribute over unions correctly, but what I find most concerning is that unknown[] has appeared out of thin air. It used to be export declare const fun: (subFun: <Collection, Field extends keyof Collection>() => (Collection[Field] extends readonly (infer InnerArr)[] ? InnerArr : Collection[Field])[]) => void which was correctly generic, if not distributive, however the inner infer has suddenly evaporated now - that's definitely not right. I'm guessing something is being over-instantiated during construction of the new wrapper in this recursive type alias case.
Activity
weswigham commentedon Jun 16, 2022
Hm, so our old emit was compatible, true, but it didn't execute over unions correctly. The new emit was introduced to distribute over unions correctly, but what I find most concerning is that
unknown[]has appeared out of thin air. It used to beexport declare const fun: (subFun: <Collection, Field extends keyof Collection>() => (Collection[Field] extends readonly (infer InnerArr)[] ? InnerArr : Collection[Field])[]) => voidwhich was correctly generic, if not distributive, however the innerinferhas suddenly evaporated now - that's definitely not right. I'm guessing something is being over-instantiated during construction of the new wrapper in this recursive type alias case.