Skip to content
This repository has been archived by the owner on Oct 5, 2021. It is now read-only.

Enumerating object fields (object spread operator, etc.) #86

Open
zxti opened this issue Dec 4, 2018 · 2 comments
Open

Enumerating object fields (object spread operator, etc.) #86

zxti opened this issue Dec 4, 2018 · 2 comments

Comments

@zxti
Copy link

zxti commented Dec 4, 2018

Typewiz seems to change objects by replacing their fields with property getters and setters—this makes sense, since it needs to track the types of the values being written.

However, wherever one uses something like Object.assign(), the spread operator, lodash.extend, etc., things seem to break—these functions aren't able to enumerate the fields (since they aren't real fields).

Do you have any suggestions on dealing with this? Thanks!

@urish
Copy link
Collaborator

urish commented Dec 4, 2018

I spent some time thinking about this, and I think using Proxy objects (along with some decorators) could do the trick. I prototyped something quick here, just to check feasibility:

https://stackblitz.com/edit/typewiz-proxy-experiment?file=index.ts

(check out the console output when running this example)

It seems like this would do the trick for the most part, except for tracking properties that are assigned value during the construction of the object. Can you please check if this approach would work better with the functions you mentioned?

@urish
Copy link
Collaborator

urish commented Dec 5, 2018

@MadaraUchiha @benjamingr perhaps you have some idea how to do it better?

Currently, typewiz replaces properties with setter/getters, so we can instrument the setters. I was thinking about using Proxy object, so this is more transparent to the user. However, it seems like this will miss everything that happens inside the constructor, unless there is some creative way to proxy the this within the constructor too?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants