chanzuckerberg / sorbet-coerce

A type coercion lib works with Sorbet's static type checker and type definitions
https://rubygems.org/gems/sorbet-coerce
MIT License
29 stars 13 forks source link

Allow configuration for erroring on unknown keys #60

Open hlascelles opened 2 years ago

hlascelles commented 2 years ago

Potential new feature

It may be useful to allow sorbet-coerce to blow up on unknown keys

Steps to reproduce:

class Foo < T::Struct
  const :bar, String
end

TypeCoerce[Foo].new.from({ bar: "Hello", foo: "New key!" })
# => <Foo bar="Hello">

# The above succeeds, but I'd like it to (configurably) blow up as `foo` is not known.

Versions:

I re-re-read the docs but don't think it is currently possible. Is it, and if not would you like it to be, when configured?

mattxwang commented 2 years ago

Hi @hlascelles, this sounds like a reasonable feature request. Are you interested in implementing the feature/creating a PR? If not, I can add it to my backlog!

hlascelles commented 1 year ago

Sorry for the delay... Just nipped this comment in before the anniversary.

If you think it would be quick for you, that would be great, please do add to backlog! I may try and have a go at some point myself, but not sure when...

mattxwang commented 1 year ago

No worries @hlascelles! Unfortunately I don't work at CZI anymore (and don't have the keys to push, make releases, etc.). Hopefully someone else on the team could help you out - they should be able to cut a release if you open a PR yourself!