# === for enum types and type safety

**URL:** https://discourse.dry-rb.org/t/for-enum-types-and-type-safety/655
**Category:** dry-types
**Created:** [November 23, 2018, 6:15pm UTC](https://discourse.dry-rb.org/t/for-enum-types-and-type-safety/655 "2018-11-23T18:15:03Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![waiting-for-dev](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/waiting-for-dev/32/71_2.png) [@waiting-for-dev](https://discourse.dry-rb.org/u/waiting-for-dev)
#### Post date: [November 23, 2018, 6:15pm UTC](https://discourse.dry-rb.org/t/for-enum-types-and-type-safety/655/1 "2018-11-23T18:15:03Z")

</div>

I have noticed the following:

```ruby
MyEnum = Types::Strict::Symbol.enum(:a, :b)
MyEnum[:a] === :a
# =>true

```

Don’t you think that it is breaking the type safety that it should provide? I mean, I think it should guarantee that you are not going to use a wrong `MyEnum` in any case, but if you can use plain symbols in place you are overpassing it. For example:

```ruby
def test(x)
  case x
  when MyEnum[:a]
    "a"
  when MyEnum[:b]
    "b"
  else
    "I shoould have raised"
end

test MyEnum[:c]
# => Dry::Types::ConstraintError ...
test :c
# => "I should have raised"

```

---

<div class="post-metadata">

### Author: ![flash-gordon](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/flash-gordon/32/494_2.png) [@flash-gordon](https://discourse.dry-rb.org/u/flash-gordon)
#### Post date: [November 24, 2018, 5:23pm UTC](https://discourse.dry-rb.org/t/for-enum-types-and-type-safety/655/2 "2018-11-24T17:23:48Z")

</div>

I’m afraid I either don’t follow or you simply expect from dry-types what’s not possible. `MyEnum[:a]` in your example returns `:a` back, it’s a symbol, not something dry-types-related. After that you call `===` on that object and, again, it’s Symbol’s behavior, not one from dry-types. And note that semantically-wise `===` cannot raise an exception in any case. If you want to get a constraint error use `MyEnum[x]`.

---

<div class="post-metadata">

### Author: ![waiting-for-dev](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/waiting-for-dev/32/71_2.png) [@waiting-for-dev](https://discourse.dry-rb.org/u/waiting-for-dev)
#### Post date: [November 25, 2018, 4:12pm UTC](https://discourse.dry-rb.org/t/for-enum-types-and-type-safety/655/3 "2018-11-25T16:12:25Z")

</div>

Oh, sorry!! Apologies… it was Friday evening after a tiring week O\_o

It was my first time using `dry-types` and I made wrong assumptions. I didn’t realize that `[]` method returned the underlying ruby primitive. Instead, I supposed it was returning an instance representing a `dry-type` value.

I see that, with current design, all the responsibility of type safety relies on the callee, while the caller can always send everything he wants. This is different than in a static typed language, but surely it is what makes more sense in a dynamic language like ruby. Otherwise `dry-types` surely would become a too invasive dependency.
