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
NoInfer interfere with Exclude in Exclude<NoInfer<I>, undefined>` #60594
typeExcludeUndefined<R>=Exclude<NoInfer<R>,undefined>;letn1: ExcludeUndefined<number|undefined>=undefined;// okletn2: ExcludeUndefined<Number|undefined>=undefined;// not excludedlets1: ExcludeUndefined<string|undefined>=undefined;// oklets2: ExcludeUndefined<String|undefined>=undefined;// not excludedletd1: ExcludeUndefined<Date|undefined>=undefined;// not excludedletarr1: ExcludeUndefined<number[]|undefined>=undefined;// not excludedletobj1: ExcludeUndefined<{}|undefined>=undefined;// okletnull1: ExcludeUndefined<null|undefined>=undefined;// ok
🙁 Actual behavior
undefined is not consistantly excluded.
🙂 Expected behavior
undefined should be consistantly excluded.
Additional information about the issue
No response
Reacted by Joe Calzaretta, Shannon V.C., Samuel Fernández and bjarketrux
What if you have a function whose return type involves NoInfer because you don't want it to be inferred from the variable to which you assign it? I mean, if you have a function that looks like declare function foo<T>(⋯): Exclude<NoInfer<T>, undefined> then you could end up with foo<Date | undefined>(⋯) producing one of these things.
I agree with Joe Calzaretta (@jcalz) and NoInfering within a return type is actually something I recommended last month to somebody as a fix for their problems. It's a legit pattern.
Activity
RyanCavanaugh commentedon Nov 27, 2024
This isn't a supported way to use
NoInfer. Not sure what the intent of this is.jcalz commentedon Nov 28, 2024
What if you have a function whose return type involves
NoInferbecause you don't want it to be inferred from the variable to which you assign it? I mean, if you have a function that looks likedeclare function foo<T>(⋯): Exclude<NoInfer<T>, undefined>then you could end up withfoo<Date | undefined>(⋯)producing one of these things.Andarist commentedon Nov 28, 2024
I agree with Joe Calzaretta (@jcalz) and
NoInfering within a return type is actually something I recommended last month to somebody as a fix for their problems. It's a legit pattern.JeanMeche commentedon Nov 28, 2024
I noticed that
NoInfer<Exclude<R, undefined>>actually works, but does it break theNoInferbehavior ?Andarist commentedon Nov 28, 2024
It shuldn't break it. Whatever is wrapped with
NoInfershouldn't be inferred into. It's an early exit ininferFromTypes:typescript-bot commentedon Dec 1, 2024
This issue has been marked as "Not a Defect" and has seen no recent activity. It has been automatically closed for house-keeping purposes.