-
Notifications
You must be signed in to change notification settings - Fork 14
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
Truly "empty" type constructors? (Disallow passing arguments) #44
Comments
Maybe the never type? |
I tried never and it asked me to provide an argument of type never (like pass it anything and cast to never). Maybe, I misused it somehow? |
Ah, yeah, that won't work, because then you'd never be able to construct an instance of that variant. This is a tricky issue. As usual structural typing is a double-edged sword. Sometimes it's useful that a function with a top type as argument (or no argument) can accept any input... other times you want to be warned that you're throwing away information. I'm not sure what the right answer is. |
I ran into this same issue (well, similar) in some code I've been writing based on some ideas by gcanti (fp-ts). It wasn't exactly the same, but it was similar in that types with nothing but a tag (no additional props) introduced a I was able to solve it by using conditional typing and an I think we could probably do something similar with unionize. Basically, we'd modify the bit that builds the constructor functions and explicitly look for that I think using |
@joshburgess I'd need to see a more concrete proposal for what you have in mind, it's all a bit abstract to me right now. |
@pelotom No prob. As soon as I'm done with what I'm working on I'll clone unionize and try to implement the same idea to demonstrate. |
@joshburgess Where did you get to on this? Essentially the problem I think we're trying to solve is this, right? declare const constructor: (type: {}) => any
// no error!!
constructor({ foo: 1 }) |
Hi, I was recently playing around with unionize and discovered that using
{}
to represent members of the union which take no arguments doesn't actually prevent you from passing arguments through in the functions passed tomatch
via the type constructors. I think, ideally, you would receive a type error when trying to pass any argument at all due to that being the intention of modeling a simple, "empty" type.Do you have any ideas for how this could be made to work? Is it possible?
The text was updated successfully, but these errors were encountered: