-
Notifications
You must be signed in to change notification settings - Fork 51
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
type:hassubtypeof #101
base: master
Are you sure you want to change the base?
type:hassubtypeof #101
Conversation
Haven't read this yet, but just wanted to say that this is, in general, a reasonable idea and something we'd like to consider, for sure. The devil is in the details, but this was originally part of the plan and got cut to scope down the MVP for user-defined type functions. |
…ore clearly describes what they do
| ------------- | ------------- | ------------- | | ||
| `hassubtype(arg: string)` | `boolean` | returns true if self has a subtype of the same tag as the argument. List of available tags: "nil", "unknown", "never", "any", "boolean", "number", "string", "singleton", "negation", "union", "intersection", "table", "function", "class" | | ||
| `hassubtypeof(arg: type)` | `boolean` | returns true if self has a subtype of the argument. | | ||
| `musthavesubtype(arg: string)` | `boolean` | returns true if self has only a subtype of the same tag as the argument. List of available tags: "nil", "unknown", "never", "any", "boolean", "number", "string", "singleton", "negation", "union", "intersection", "table", "function", "class" | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't have an idea on what the description for the musthave
methods should be, so its just the same as the has
methods.
Making this not a draft as its much more well described now, plus to hopefully have someone contribute a description for the |
Would an exact method be a good idea to include aswell? Although It'd be basically rendered useless by generic constraints. But It'd basically not allow unions when the provided subtype isnt a union. type meow = {
hi: string
}
type mrrp = {
hi: "hello"
}
type meowers = meow | mrrp
print(meowers:exacthassubtypeof(meow)) -- false
print(mrrp:exacthassubtypeof(meow)) -- true |
You seem to be too focused on hard-coding some behaviors exactly targeting unions, which leads to the problems of structural subtyping. So to me, having anything aside from |
Yeah, the rest would be better solved with generic constraints admittedly. |
Removed everything else and just left |
Proposes adding a new method to the type userdata for subtype checking.
Rendered