mwbot-ts - v1.2.8
    Preparing search index...

    Type Alias OnlyOneRecord<K, V>

    OnlyOneRecord: {
        [P in K]: (Record<P, V> & Partial<Record<Exclude<K, P>, never>>) extends infer O
            ? { [Q in keyof O]: O[Q] }
            : never
    }[K]

    Constructs a type in which only one key in K can have the value in V.

    // Error
    const ex1: OnlyOneRecord<'a' | 'b', { 1: 1 }> = {
    a: { 1: 1 },
    b: { 1: 1 }
    };
    // Ok
    const ex2: OnlyOneRecord<'a' | 'b', { 1: 1 }> = {
    b: { 1: 1 }
    };

    Type Parameters

    • K extends string
    • V = any