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
There are many valid ways to display the same type. Some are clearer than others.
TypeScript gives you some tools to control how types display, notably the Resolve generic. Make judicious use of this to clarify type display and hide implementation details.
Consider handling important special cases of generic types to improve type display.
Write tests for your generic types and their display to avoid regressions.
Code Samples
typeT123='1'|'2'|'3';// ^? type T123 = "1" | "2" | "3"
typeS=ObjIdentity<string>;// ^? type S = stringtypeN=ObjIdentity<number>;// ^? type N = numbertypeU=ObjIdentity<'A'|'B'|'C'>;// ^? type U = "A" | "B" | "C"
typePartiallyPartial<Textendsobject,KextendskeyofT>=[K]extends[never]
? T// special case
: Textendsunknown// extra conditional to preserve distribution over unions
? Resolve<Partial<Pick<T,K>>&Omit<T,K>>
: never;typeFullComment=PartiallyPartial<BlogComment,never>;// ^? type FullComment = BlogComment