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
I've made some utility types similar to existing types
It is useful, so I am using it on every typescript projects by declaring on global namespace.
I will introduce one by one.
ValueOf
This type returns all of the type of value of object(Record)
typeValueOf<T>=T[keyofT];//exampleconsta: Record<string,number|string>={};typevalueof_a=ValueOf<typeofa>;// number | string
TypeGuard
This type returns type that the typeguard is guarding
typeTypeGuard<Textends(args: any)=>any>=Textends(args: any,)=>args is infer R
? R
: any;//examplefunctionstringGuard(data: any): data is string{returntypeofdata==='string';}typestring_guardingType=TypeGuard<typeofstringGuard>;//stringfunctionnumberGuard(data:any) : data is number{returntypeofdata==='number';}typenumber_guardingType=TypeGuard<typeofnumberGuard>//number
Nullish
This type adds null to all of the values of object
Suggestion
π Search Terms
Util types, Utility types, etc...
β Viability Checklist
My suggestion meets these guidelines:
β Suggestion
I've made some utility types similar to existing types
It is useful, so I am using it on every typescript projects by declaring on global namespace.
I will introduce one by one.
ValueOf
This type returns all of the type of value of object(Record)
TypeGuard
This type returns type that the typeguard is guarding
Nullish
This type adds null to all of the values of object
Arrayify
This type arrayifies all the object's value.
If you decided to add this but the name seems to be inappropriate, I won't mind to change the name of types. But let me know the new name.
π Motivating Example
This improves the usability of the language. It can be used by creating like I did, but it would be better when it is already built-in.
π» Use Cases
I've written all the examples above.
The text was updated successfully, but these errors were encountered: