@x_m/type-utils
v0.1.9
Published
type utils
Downloads
1
Readme
@x_m/type-utils
typescript 类型辅助函数
install
yarn add @x_m/type-utils
examples
PickOneOf
from: https://dev.to/maxime1992/implement-a-generic-oneof-type-with-typescript-22em
interface Group {
num: number[]
str: string[]
boo: boolean[]
}
/**
* PickOneOfGroup is {
* num: number[]
* str: undefined
* boo: undefined
* } | {
* num: undefined
* str: string[]
* boo: undefined
* } | {
* num: undefined
* str: undefined
* boo: boolean[]
* }
*/
type PickOneOfGroup = PickOneOf<Group>
StructAs
interface Group {
num: number[]
str: string[]
boo: boolean[]
}
/**
* StructedGroup is {
* type: 'num'
* value: number[]
* } | {
* type: 'str'
* value: string[]
* } | {
* type: 'boo'
* value: boolean[]
* }
*/
type StructedGroup = StructAs<Group, 'type', 'value'>