oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
74.53k stars 2.79k forks source link

Runtime Reflection API #6006

Closed Pandapip1 closed 6 months ago

Pandapip1 commented 1 year ago

What is the problem this feature would solve?

There are number of use cases for a runtime type checking/reflection API. For example, I want to make a helper to turn objects into C structs compatible with Bun FFI and vice versa. However, the 'vice versa' part isn't possible because you can't get the typescript data of an object at runtime.

What is the feature you are proposing to solve the problem?

An API like https://rttist.org/, but for Bun.

What alternatives have you considered?

No response

Jarred-Sumner commented 6 months ago

JavaScript is a dynamic language

You can use typeof, instanceof, and so many more language features to support runtime reflection. You can also use TypeScript experimental decorators.