1

I'm working with a web api project involving typescript. It's not recognizing the jquery symbol $ in the typescript files. Google says all I have to do is this:

npm install --save @types/jquery

It doesn't work.

I know this depends on package.json being available. What does package.json have to look like?

1

2 Answers 2

2

If this is a Visual Studio project that doesn't have npm set up, there are a couple of other ways to do this. The best is probably to install the NuGet package jquery.form.TypeScript.DefinitelyTyped, which will add the file /Scripts/typings/jquery/jquery.d.ts (at least on a classic ASP.NET project, not sure about Core.)

Another thing you can do is tell TypeScript to let you use $ without checking anything:

declare var $: any;'
Sign up to request clarification or add additional context in comments.

Comments

1

You need to make sure that your @types/* are registered in your tsconfig.json. Like this:

{
    "compilerOptions": {
        ...
        "typeRoots": [
            "./node_modules/@types"
        ],
        ...
    }
}

Another idea is to use import * as $ from 'jquery';

Comments

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.