Ways to use other JS frames or libraries in typescript

Source: Internet
Author: User

Recently contacted Typescript, feeling very strong, but also have some problems.

For example, we normally write JS, as long as the other JS library into the page, and even as long as added to the project, ReSharper will automatically analyze him, and provide grammar can only sense, write code very comfortable.

However, since Typescript is a strongly typed language, he does not allow other unknown JS libraries to be used at the moment, because there is no way to do compile detection, so how to use other JS libraries in TS becomes a problem.

Here are a few ways to find out:

1. Use declare keyword

Declare var $: any; Declare  var jquery:any;jquery (function() {    $ ("<div>"). Text ("TypeScript"). AppendTo ($ (" Body "));})

His role is to declare that the variable already exists in some other JS, but also to lose all the compiler's grammar IntelliSense, grammar check and other functions.

It is a double-edged sword.

Other about declare keywords read:

Whats the difference between "declare class" and "interface" in TypeScript


2. Using TS definition files

(not to be continued)

Ways to use other JS frames or libraries in typescript

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.