3

I started beginning to learn TypeScript. So far I am liking it. Now I have ran into an issue. When I start typing in a JavaScript file, like a function from my TypeScript file, its not showing up in intellisense. Why is this and how can I fix it so when I am working with the contents of a TypeScript file that intellisense catches it?

EDIT

Errors

Link to project

Project link

2
  • You're trying to call a TypeScript method from a JavaScript file and have it autocomplete? That's highly dependent on your IDE, I know WebStorm/IntelliJ supports it. Commented Dec 24, 2016 at 18:47
  • @PaulBGD, that is correct. I am using Visual Studio 2015.. I wonder if I should reword my question because you hit the nail on the head Commented Dec 24, 2016 at 18:50

1 Answer 1

2
+25

You have a few options available to you, it's been a little while since I've tried them out so I would recommend seeing which works for you.

1. Adding a reference comment to your JavaScript file

The JavaScript editor built into Visual Studio allows you to extend the JS intellisense by adding references to JavaScript files via the following comment that should be placed at the top of your JavaScript file.

/// <reference path="../app/your-transpiled-ts-file.js" />

2. Referencing JS files via Visual Studio's options

You can also do a similar thing on a global level via Options > JavaScript > IntelliSense > References.

See this article by Mads Kristensen for more information.

3. TypeScript's allowJs option

One of the new exciting features in TypeScript (1.8 I believe) is the allowJs flag that can be set to true within your project's tsconfig.json file.

Enabling this allows you to use TypeScript definition files within JavaScript and get the full intelliSense experience you'd expect.

Here's a video of TypeScript's creator, Anders Hejlsberg demonstrating this at the recent Build 2016 event that I'd recommend taking a look at (I've linked directly to the part where he starts to talk about the allowJs flag).

Sign up to request clarification or add additional context in comments.

9 Comments

#3 looked the most promising and this is what I did and the error that I get Created MVC Project, Updated packages, Installed jquery.TypeScript.DefinitelyTyped from NuGet, Created a New TypeScript file, Added the reference jquery.d.ts in the TypeScript file, Added TypeScript JSON Configuration file, Added "allowJs":true, and get errors: Build:Cannot Write file ... because it would override input file
Does it tell you what file you'd be overwriting? This sounds like an issue with your editor rather than TypeScript. Including TypeScript definition files should be done via NPM as of TypeScript 2.0 so it's possible there could be some conflict?
I made an edit and added a screenshot of the errors that I am getting when compiling now... I am using the editor in Visual Studio 2015
Is your source code up on GitHub anywhere? That seems an odd error. Do you have any includes such as import * as test from "../";? Could you try run tsc --traceResolutions too from your project root please?
Made another edit and added a link to the project I don't tsc or NPM, I downloaded TypeScript for VS2015, installed it and did the steps that I mentioned in an earlier comment
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.