TranscryptOrg / Transcrypt

Python 3.9 to JavaScript compiler - Lean, fast, open!
https://www.transcrypt.org
Apache License 2.0
2.86k stars 214 forks source link

Runtime Type Information #701

Open jdwil opened 4 years ago

jdwil commented 4 years ago

I don't see a way to embed type information in the transpiled JS code that can be accessed at runtime. Currently I have entities defined in Python and am converting those to JS so I can use them as view models on the front-end. Everything is working great, except that I define the entity field types using the Python typing module and this type information is lost after transpiling. Note, I'm not looking for runtime type enforcement like is currently supported with mypy... I'm looking to use reflection in the javascript to understand what types my entity properties are.

First, is this doable and I'm just missing it?

Secondly, if not, then has any thought been put into this? The type information for class properties could be stored in some type of metadata field on the class itself. And, maybe something similar could be done for module-level variables and function parameters?

Love this tool, btw, so thanks for the work you've put into it.

JdeH commented 4 years ago

Storing RTTI as part of the resulting JS sounds doable in many cases. Never gave that a thought. Will now, though...