Skip to content
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

[RFC/Proposal]: Add types for modules #326

Open
RichDom2185 opened this issue Sep 23, 2024 · 0 comments
Open

[RFC/Proposal]: Add types for modules #326

RichDom2185 opened this issue Sep 23, 2024 · 0 comments
Assignees

Comments

@RichDom2185
Copy link
Member

Background

With Source Typed, it is now possible to teach strong typing at an introductory level. Naturally, it extends to modules, something that students interact with a lot in Source Academy.

Possible Considerations

The "exposed" type should be separate from the actual implemented type

To enforce abstraction principles. For example, while runes are by no means a primitive type in its implementation (using higher order functions, etc.), we should treat them as such.

Ideally, types should be inlined

https://github.com/source-academy/js-slang/pull/1467/files#diff-2e2aa2db6619eec1be92cd4c227f51bafd0c3e8a0ba28a58c105e5e08944ec5d gave a proposed method of defining types for modules. However, not only are they located in a separate file, they are located in an entirely different repository (and NPM package). This makes keeping consistent type definitions difficult.

Ideally, we should be able to define the types of members we want to type, as well as "type aliases", inline, as much as possible.

Proposal

We propose writing a custom esbuild plugin to handle this use-case. It will be transparent, requiring minimal-if-no changes to existing modules to leave them untyped.

Using decorators attached to each name we want to type, the hope is we can generate the metadata/type definitions not unlike the one above, during build/bundle time, based on the values supplied in the decorator.

Feasiblity

Will need to investigate.

See also

source-academy/js-slang#1400 (and related hyperlinks within)

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

No branches or pull requests

3 participants