All files / src TProperty1Extensions.ts

33.33% Statements 2/6
100% Branches 0/0
0% Functions 0/2
33.33% Lines 2/6

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 16 17 18                  1x     1x          
// Package: com.lightningkite.lightningdb
// Managed here.
import {Comparator, DataClass, hashString, tryCastClass} from '@lightningkite/khrysalis-runtime'
 
//! Declares com.lightningkite.lightningdb.PartialDataClassProperty
export type PartialDataClassProperty<T> = keyof T & string
//! Declares com.lightningkite.lightningdb.DataClassProperty
export type DataClassProperty<T, V> = keyof { [ P in keyof T as T[P] extends V ? P : never ] : P } & keyof T & string;
 
export function keyGet<K, V>(on: K, key: DataClassProperty<K, V>): V {
    return on[key] as unknown as V
}
export function keySet<K, V>(on: K, key: DataClassProperty<K, V>, value: V): K {
    const dict: Record<string, any> = {}
    dict[key] = value
    return (on as unknown as DataClass).copy(dict) as unknown as K
}