All files / src ts-prop.ts

44.44% Statements 4/9
100% Branches 0/0
25% Functions 1/4
44.44% Lines 4/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 161x 1x     1x 2x                    
import {compareBy, DataClass} from "@lightningkite/khrysalis-runtime";
import {DataClassProperty} from "./DataClassProperty";
 
 
export function prop<K extends DataClass, KEY extends keyof K & string>(key: KEY): DataClassProperty<K, K[KEY]> {
    return new DataClassProperty(
        key,
        x => x[key],
        (a, b) => {
            const dict: Partial<K> = {}
            dict[key] = b
            return a.copy(dict)
        },
        compareBy(x => x[key])
    )
}