Skip to content

类型体操

部分可选

ts
interface Art {
    title: string;
    content: string;
    tag: string[];
    time: string;
}

type Key = keyof Art; // title | content | tag | time

let key: Key
type Optional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>
const op: Optional<Art, 'tag' | 'time'> = {
    title: '12232',
    content: '342323',
    tag: ['32323'],
    time: '243232',
}