Add packages/common/src/types.ts
This commit is contained in:
parent
2f17418753
commit
0a9648c392
@ -12,4 +12,5 @@ export * from './IUserTeam'
|
||||
export * from './ReadonlyRecord'
|
||||
export * from './URLFormatter'
|
||||
export * from './indexBy'
|
||||
export * from './types'
|
||||
export * from './without'
|
||||
|
||||
22
packages/common/src/types.ts
Normal file
22
packages/common/src/types.ts
Normal file
@ -0,0 +1,22 @@
|
||||
/**
|
||||
* transform unknown into undefined
|
||||
*/
|
||||
export type Optional<T> = T extends {} ? T : undefined
|
||||
|
||||
export type NonUndefinedPropertyNames<T> = {
|
||||
[K in keyof T]: T[K] extends undefined ? never: K
|
||||
}[keyof T]
|
||||
|
||||
export type OnlyRequired<T> = Pick<T, NonUndefinedPropertyNames<T>>
|
||||
|
||||
export type NonUnknownPropertyNames<T> = {
|
||||
[K in keyof T]: T[K] extends {} ? K : never
|
||||
}[keyof T]
|
||||
|
||||
export type OnlyDefined<T> = Pick<T, NonUnknownPropertyNames<T>>
|
||||
|
||||
/**
|
||||
* Remove types from T that are not assignable to U
|
||||
* https://www.typescriptlang.org/docs/handbook/advanced-types.html
|
||||
*/
|
||||
export type Filter<T, U> = T extends U ? T : never
|
||||
Loading…
x
Reference in New Issue
Block a user