-
-
Notifications
You must be signed in to change notification settings - Fork 47
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
Proxy support #33
Comments
The more I investigate implementing this, the more it grows in scope. Are we interested in ensuring that the Proxy handler returns values that respect the type definition of the proxied type? For example, we could implement a Proxy like the following: type SomeType = {
a: number
}
const handler = {
get(_target: SomeClass, _propKey: keyof SomeType) {
return "invalid"
}
}
const proxiedType = new Proxy<SomeType>({ a: 4 }, handler)
const b: number = proxiedType.a The above proxy is invalid because the |
Hmm yes looking at this there is quite a lot to cover. I think the first step would to be get const p = new Proxy({}, { get(target, key) { return key });
print_type(p.something) to print I think the last time I attempted it there were some pieces missing in the checker and I couldn't create a Will have another look today, I think it might be possible now. I will try and get the foundation wired up, so others can tie up and test the trap logic. Type checking is harder: how can we know that |
Hey @PatrickLaflamme, I have added some of the Proxy constructor stuff for #146 so this looks good to start on if you want to give it a crack. Firstly So for the parts left to implement: I have created a branch for the property access logic here ezno/checker/src/types/properties.rs Lines 513 to 516 in bdac106
You basically want to get the trap type of handler and then call it with all the relevant information. As you implemented setters in #138 you should be proficient. Once you can get the example above working in a PR const p = new Proxy({}, { get(target, key) { return key });
print_type(p.something) then setting and calling should be okay. Can ignore other traps for the first iteration. I have some ideas for subtyping but they can also be worked out later. |
75% done in #157 See new tests: https://github.com/kaleidawave/ezno/blob/main/checker/specification/specification.md#proxy There are still some "traps" that are not implemented. Only |
As much as want it not to exist. I guess it needs to be supported.
Steps
ObjectNature
which isProxy { trap: TypeId }
get_property
andset_property
to call a function ifon
has this structureTODO
The text was updated successfully, but these errors were encountered: