-
Notifications
You must be signed in to change notification settings - Fork 15
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
Proposal: New API + set of types for working with blocks in a type-safe way #93
Comments
Here's your notes from #94, for reference:
|
@adroitwhiz I'm trying to understand how this issue and #100 are separate a bit better. It seems like they largely address the same areas, reworking overall API structure to improve type safeness, expand library capabilities, and tidy code style and structure legibility. I'm interested if you feel there are separate things/goals they address, or if #100 was more of a follow-up detailing a specific example of why the overall rework discussed here is necessary? |
#100 was something I discovered after writing this issue. I think this issue better describes my proposed solution (in retrospect) |
Yeah, it felt more like a diagnosis of an issue via description of symptoms rather than a detailed way forward, which is mostly covered here. |
There are a lot of issues with the current block/opcode API that we seem to keep running up against:
BlockBase
type signature for each individual block, but also store that data at runtime inKnownBlockInputMap
.getDefaultInput
is very loosely typed, as it cannot make use of said type information.getDefaultInput
because they depend on a built-in list of known blocks.I propose to fix this by moving blocks' opcode + input data into runtime-accessible "type objects". Each defined block would have an immutable "block prototype" instance, which can be queried both at runtime and compile-time (since it's immutable, the TypeScript compiler can read its fields). This solves our issues nicely:
typeof
operator (not to be confused with JavaScript's runtimetypeof
), which allows us to provide static-type guarantees.Here's some proof-of-concept code I wrote which demonstrates this approach:
Type definitions w/ demo code
The text was updated successfully, but these errors were encountered: