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.
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
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.
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
The one extra step is to create a
package-types.json file to configure the
.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.
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.