Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Field Type is not being enforced #41

Closed
pradeep-in opened this issue Oct 11, 2022 · 1 comment
Closed

Field Type is not being enforced #41

pradeep-in opened this issue Oct 11, 2022 · 1 comment
Labels
R:Duplicate Rejection reason: Duplicate

Comments

@pradeep-in
Copy link

pradeep-in commented Oct 11, 2022

It doesn't make a lot of sense for me to just define the types and not enforce.

Example -
I create a typed struct like this -

defmodule WhatEver do
 use TypedStruct

  typedstruct do
    field :SomeField, List.t()
  end
end

and then it is still allowing this to be set other than list -

struct(WhatEver, %{SomeField: 123})

> %WhatEver{SomeField: 123}

Would make more sense if it could actually validate the type.
At first, it gives this false impression that it would validate it, but it doesn't.

Even with using enforce: true, it just checks for the key to be present. Not the type.

@ejpcmac
Copy link
Owner

ejpcmac commented Oct 11, 2022

typed_struct helps you define a @type for a given struct by writing less code, it does not check anything. You then need to use Dialyzer or other type-checking tools to type-check your code. This is how Elixir currently works.

Domo is known to work with TypedStruct, though I’ve not used it myself yet.

I’m closing this one as it is essentially a duplicate of #3.

@ejpcmac ejpcmac closed this as completed Oct 11, 2022
@ejpcmac ejpcmac added the R:Duplicate Rejection reason: Duplicate label Oct 11, 2022
@ejpcmac ejpcmac moved this from Solved to Rejected in ejpcmac’s personal OSS work Dec 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
R:Duplicate Rejection reason: Duplicate
Projects
Status: Rejected
Development

No branches or pull requests

2 participants