Andy Chen Andy Chen - 2 months ago 20
TypeScript Question

How to reference @types/module in typescript?

After I install module like

@types/express
via
npm
, how do I reference it in typescript?

I have try followings :


  1. /// <reference path="../node_modules/@types/express/index.d.ts" />
    still give me
    can not find module 'express'
    error

  2. import * as express from '@types/express';
    can pass the typescript compilation, but after compile will be
    require('@types/express')
    which should be
    require('express')
    instead.


Answer

That is a TypeScript 2.0+ plus. It will not work with versions earlier than that.

As of now 2.0 is still in beta but is available as the typescript@beta version. To install i run:

npm install -g typescript@beta