1

Does Microsoft's Typescript Sublime Plugin (https://github.com/Microsoft/TypeScript-Sublime-Plugin) include a linter? When I select View > Syntax > Typescript, a linter tells me that require is not defined:

enter image description here

Is this linter from Microsoft's plugin? I removed all other possibly responsible Sublime packages, but there is nothing in the documentation about the linter. And how do I get it to stop complaining about the require?

2 Answers 2

1

include a linter

Depends upon your definition of linter. TypeScript as a whole can be considered a powerful JavaScript linter + TypeScript transpiler (more)

Is this linter from Microsoft's plugin

Yes.

Quick fix

Because you don't have require function defined. You should include node.d.ts in your project.

Better fix

And even better include phantom.d.ts and use import/require.

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

2 Comments

Where do I put .d.ts files?
anywhere that they would get picked up by tsconfig.json
1

No, it doesn't.

You need to use an import statement in TypeScript:

import a = require('phantom');

Also, make sure to have phantom's type declaration file—phantom.d.ts—in your project.

5 Comments

When I use that syntax, it tries to locate the module even when I'm just cross-compiling the typescript to javascript and not actually running the javascript.
@TahsisClaus you need to tell typescript about that module by providing it the phantom.d.ts file in your project. The common way is to put it in a typings folder like typings/phantom/phantom.d.ts (this is what tsd does if you run tsd install phantom in the root directory of your project)
Do I have to provide the compiler the file route somehow? I used tsd install phantom and the compiler still throws an error abotu not being able to find it.
@TahsisClaus I feel like it should work if you can see the file already in sublime. I'm not as familiar with the sublime plugin though. You might have to add /// <reference path="replace/with/relative/path/to/phantom.d.ts" /> to the top of your file or reference it in a tsconfig.json file.
I got it to work after changing an option for gulp-typescript, though it can't find module 'webpage' (a phantomjs module), so I'm not actually sure it sees the phantom.d.ts file.

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.