vscode icon indicating copy to clipboard operation
vscode copied to clipboard

Type Definition imports not working for *.ts files

Open jalipert opened this issue 11 years ago • 2 comments

A couple things related to type definitions don't seem to work for *.ts files (features currently working fine for *.js files).

  1. Green underlining with "Download type definition" suggestion does not appear. Instead, just a red underline with message "Cannot find name xxxxx"
  2. Project-wide type definition references do not automatically load in *.ts files.

A workaround is manually pasting the relevant /// includes at the top of every *.ts file.

jalipert avatar Nov 18 '15 20:11 jalipert

Project-wide type definition references are supported using tsconfig.json. See https://code.visualstudio.com/docs/languages/typescript for the difference between File scope and project scope.

Supporting download of d.ts files is on our list.

dbaeumer avatar Nov 19 '15 10:11 dbaeumer

In addition to @dbaeumer's tsconfig.json suggestion, TypeScript now also supports managing Typings files using npm: https://blogs.msdn.microsoft.com/typescript/2016/06/15/the-future-of-declaration-files/

$ npm install --save@types/express

These typings are then automatically loaded, without needing <reference path="...">:

import express from 'express';

...

A lot has changed in the last year, so please take a look at the updated typings management story and let up know if you have any suggestions or ideas for improvement. Thanks.

mjbvz avatar Nov 29 '16 22:11 mjbvz