# Type Fixing

**URL:** <https://es.discourse.group/t/type-fixing/918>\
**Category:** 💡 Ideas\
**Tags:** proposal\
**Created:** [August 11, 2021, 3:14pm UTC](https://es.discourse.group/t/type-fixing/918 "2021-08-11T15:14:37Z")\
**Posts on this page:** 1\
**Showing post:** 9

<div class="post-metadata">

**Author:** ![theScottyJam](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/thescottyjam/32/616_2.png) [@theScottyJam](https://es.discourse.group/u/theScottyJam)\
**Post date:** [August 11, 2021, 7:11pm UTC](https://es.discourse.group/t/type-fixing/918/9 "2021-08-11T19:11:12Z")

</div>

OK, those are fair arguments.

I'm just going to point out an alternative solution to providing type assertions. In [this thread](https://es.discourse.group/t/catch-error/904/2), I had brought up an idea of using a "from" keyword, to allow arbitrary operations to happen during assignment. I believe @mmkal might be making a separate topic soon to discuss it more fully. This would allow us to do things like the following:

```javascript
const assertNumb = n => {
  if (typeof n !== 'number') throw new Error('Bad type!')
  return n
}

function addNumbs(x from assertNumb, y from assertNumb) {
  return x + y
}
// is the same as this:
function addNumbs(x_, y_) {
  let x = assertNumb(x_)
  let y = assertNumb(y_)
  return x + y
}

```

A library of different type assertions could be created, that could be inlined into any declaration position. These assertions could become very rich, e.g. you could assert that a number was even, or that a string matched a regex, etc.

Just an alternative direction I thought I would point out.

It doesn't help with the scenario of making sure a local variable stays the same type, even after assignment. But, IMO, that's not a big deal, because ideally reassignment should be kept to a minimum. I would do zero reassignment if the language provided the facilities to do so, but things like try-catch don't make it easy to avoid reassignment.

It also doesn't help with object members. This would be a place where your proposal has certain strengths over the one I'm proposing.

---

_[View the full topic](https://es.discourse.group/t/type-fixing/918)._
