Skip to content

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

Notifications You must be signed in to change notification settings

IKoshelev/ts-swap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

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

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published