Typescript types for Javascript in Rails

Currently, there are no built in Typescript type definitions for Javascript in Rails. The lack of types definitions can make using Rails packages from Typescript more difficult than necessary. I propose we start adding these type definitions in the Rails repository so they can be included in the built packages and are automatically available for Typescript users. I’m happy to begin with the ActiveStorage JavaScript library as that’s an area of interest for me if folks are onboard with this idea.

As background for those not familiar with Typescript, types for a dependent package are required for building Typescript projects. If the dependent package does not include types themselves, they can be maintained separately of the repository by the end-user or in another package, usually hosted in the DefinitelyTyped repository. These types often diverge over time from the official packages as changes are made but the external types are not updated.

One major advantage of the Typescript definitions is that, in development environments like VSCode, there is autocomplete as you type. This makes it easier for new developers to get up to speed quickly and able to explore the API as they learn.

For those wondering, type files for non-Typescript projects do not require any additional dependencies. They’re a simply files that get added to the repository and a single types field is added to the package.json which includes a path to where the main type file is located in the package.

One note though is that if type files are added, updating type files should be part of the process of submitting changes to the external API for a Rails javascript package. If not, there’s a risk of divergence like in externally managed type definitions.

2 Likes

Don’t mean to poke the bear but is there anyone involved in the Javascript side interested in this? It requires a bit of change to process to really make it work so if no one is interested in doing that, they can stay outside the Rails repo.

1 Like

Thank you for the suggestion but I don’t think we have interest in maintaining type information for JavaScript inside Rails at this point. I think the main path forward is having community maintained package for them.

1 Like