0.0.2 • Published 5 years ago

ts-swap v0.0.2

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

Swap values of 2 keys, with compile time type check for compatibility

Swap values of 2 keys, with compile time type check for compatibility

import { swap } from 'ts-swap'
  const t = {
    a: 1,
    b: 2,
    c: '',
    c1: '',
    d: { a: 5 },
    e: { a: 6 },
    f: { b: 7 },
    g: { a: '' }
  }
 
 swap(t, 'a', 'b');
 swap(t, 'a', 'c'); //error
 swap(t, 'b', 'c'); //error
 swap(t, 'a', 'a'); //error
 swap(t, 'c', 'c1');
 swap(t, 'd','e');
 swap(t, 'd','f'); //error
 swap(t, 'd','g'); //error