Skip to content

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

@RichDom2185

Description

@RichDom2185

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)

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions