How to access Assets API from typescript?


I cannot for my life figure out how to invoke api methods like Assets.

The typings for Assets declare it to live in “meteor/tools” but that package doesn’t seem to exist so that was a no go and I also couldn’t figure out how to write my own index.d.ts file to make Assets methods available.

Can anyone help out?



Assets is global and doesn’t have an import path (because it loads very early in Meteor’s lifecycle), so you can only use it as a global.

Not 100% on the typescript part, but it sounds like you just have to tell typescript that it exists and give it a type?

declare var Assets: any;


I could not get that to work - for some reason the Assets variable is not accessible for typescript code - when running the code it comes up as undefined also when accessing it in the js console.

This is what I tried (and failed)

declare module "meteor/meteor" {
  import * as tools from "meteor/tools";
  export var Assets: typeof tools.Assets;


Which typescript package are you using? I’ll try it out


I use adornis:typescript at version 0.9.9 (Typescript 3.4) and then in my using code

import { Meteor, Assets } from “meteor/meteor”

Assets.getAbsoluteFilePath(“asdfasdf”) <== cannot call getAbsoluteFilePath of undefined


As I said in the first reply, there is no import for Assets, it’s a global, just use it directly.

To suppress the typescript warnings, you can add a type declaration like so:

declare var Assets: any;

import { Meteor } from “meteor/meteor”


I’ve tested this in adornis:typescript and barbatus:typescript