Using jQuery plugins inside a Typescript file

This is the first time I'm using typescript in my company's projects, and I have this JS file:

/// <reference path="jquery.d.ts" />
/// <reference path="bootstrap-switch.d.ts" />    
function CreateIdeSkuValidoSwitch() {
     $("[name='actived_ideskuvalido']").bootstrapSwitch();
}

But when I use this in my typescript function, the compile say: property does not exist in the 'jQuery' type.

I want to know how I use this jQuery plugin switch inside my ts files using jQuery.

Sorry, my bad english.

+4
source share
2 answers

Your question is not clear; however, from your comment, “Imagine if I have a plugin that does not have a .ts file,” you seem to be asking: how can I use the jQuery plugin, which is not yet a definition file .d.ts.

jQuery TypeScript, jQuery. TypeScript, $() - , jQuery.

, .d.ts, TypeScript.

, TypeScript, , jQuery any. , IDE - .

, , "Hello World",

(function( $ ) {
    $.fn.helloWorld = function() {  
      this.html('Hello World');
      return this;
    }
})(jQuery);

// Either the plugin author provides the definition, or you write them yourself
interface JQuery {
    helloWorld();
}

TypeScript , , .

. jQuery TypeScript

, ,

Typed - , , JavaScript TypeScript, jQuery

0

Source: https://habr.com/ru/post/1661196/


All Articles