Zodern:types Tooling for creating and using types from packages

The past couple weeks I’ve been working on zodern:types to allow packages to have their own typescript types and for apps to use them. It can be used for both apps and packages, and provides different tools for each.

Apps

For apps, it makes it possible for typescript to find the types that are in any Meteor packages the app uses. You simply add the zodern:types package to your app, and add a path mapping to your tsconfig.json.

This part of zodern:types is implemented as a linter, so the package types are updated every time the app is built. You can also update them by running meteor lint.

Even if your app doesn’t use typescript, this can still be useful when writing code:

  • the code editor can provide better auto completions and information by using the types
  • you can use the code editor’s Go to Definition feature to view the code for a package

For local packages, it can use the package’s .ts files directly so type definitions don’t have to be generated.

Packages

When publishing a package with type definitions, you have to generate the types and uninstall any npm dev dependencies before publishing. If a package depends on zodern:types, those steps are automatically done as part of meteor publish.

The one extra step is to create a package-types.json file to configure the .ts or .d.ts file to use for the package’s types (if it is a .ts file, it is used as is when it is a local package, and converted to a .d.ts file during publish).

This comment shows how universe:i18n, a package already written in typescript, could be configured to be published with types.

zodern:types can also be used for packages that aren’t written in typescript, or have another method of generating a .d.ts file. For example, montiapm:flow-router supports Meteor 1.4, which doesn’t have the typescript package. This shows how it was configured to have types.

Next steps

zodern:types is ready to use. These are the packages I’ve found so far that have been published with types:

Any local packages that are written in typescript and have a single file used as a main module will work as is. For other packages, you can follow the steps here.

17 Likes

Thank you, @zodern !

It is really cool thing which I personally waiting long time.

1 Like

Great job @zodern, I’ll give it a try this week :tada:

I released version 1.0.8 today with a number of improvements:

  • Improve performance so it takes 1/10th of the time it did before during rebuilds (in one app, it now takes 25ms per rebuild instead of 300ms)
  • Packages can now type their default export
  • The message about not having access to the package catalog is no longer shown
  • If you run meteor lint, it will now immediately exit after updating the types to avoid some bugs with meteor lint

Another package with types is react-meteor-accounts.

Meteor packages are able to use types from npm packages (react-meteor-accounts uses types from react) if you enable the preserveSymlinks option in your tsconfig.json.

6 Likes

Hey zodern could you take a look at my pr over at the GitHub repo? Currently, the package is broken with atleast meteor 3.0 on Windows.

cheers