# Variable assignments with built-in assignment filters

**URL:** <https://es.discourse.group/t/variable-assignments-with-built-in-assignment-filters/562>\
**Category:** 💡 Ideas\
**Tags:** proposal\
**Created:** [December 2, 2020, 1:37am UTC](https://es.discourse.group/t/variable-assignments-with-built-in-assignment-filters/562 "2020-12-02T01:37:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Seagat2011](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/seagat2011/32/367_2.png) [@Seagat2011](https://es.discourse.group/u/Seagat2011)\
**Post date:** [December 2, 2020, 1:37am UTC](https://es.discourse.group/t/variable-assignments-with-built-in-assignment-filters/562/1 "2020-12-02T01:37:03Z")

</div>

Assignment filters are special dynamic types that hold only 1 of its non-static data members at any one time

```javascript
let a = | 1,2,3 | // variable assignment "a" can only accept the values 1 or 2 or 3

a==1 // ReferenceError: a is not defined
a==2 // ReferenceError: a is not defined
a==3 // ReferenceError: a is not defined

a = 5 // ReferenceError: a is not defined
a = 1 // a==1

a==1 // true
a==2 // false
a==3 // false

let b = 1

switch(b){
    case a:
        console.log("This is a valid assignment for a:",a)
        break;
    default:
        console.log("ReferenceError: a is not defined for b ==",a)
        break
}

a == b // true

let c = | myIntegerNumberField(),myRationalNumberField(),myComplexNumberField() | // let c equal any rational number, discrete integer, or vector

```

(cf C++ union)

---

<div class="post-metadata">

**Author:** ![Yaffle](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/yaffle/32/900_2.png) [@Yaffle](https://es.discourse.group/u/Yaffle)\
**Post date:** [December 2, 2020, 10:33am UTC](https://es.discourse.group/t/variable-assignments-with-built-in-assignment-filters/562/2 "2020-12-02T10:33:25Z")

</div>

For now you could use Proxy to achieve similar result, Proxy allows to set the "trap" for the setter. let c = new Proxy(...);

---

<div class="post-metadata">

**Author:** ![claudiameadows](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/claudiameadows/32/126_2.png) [@claudiameadows](https://es.discourse.group/u/claudiameadows)\
**Post date:** [January 2, 2021, 6:59pm UTC](https://es.discourse.group/t/variable-assignments-with-built-in-assignment-filters/562/3 "2021-01-02T18:59:16Z")

</div>

What does this provide that things like TypeScript doesn't?
