如何在typescript文件中正确导入jqueryui

how to properly import jquery-ui in typescript file

本文关键字:导入 jqueryui 文件 typescript      更新时间:2023-09-26

我已经包含了像这个一样的jquery

import $ = require('jquery');

我正试图让一些div像这样可拖动。

constructor() {
    $("#mydiv-id").draggable();
}

但是我得到一个错误,draggable不是一个函数。我确实有jqueryui.d.ts,但如何正确导入它?

require.config类似

var require = {
paths: {
    text: '../Scripts/libs/text',
    jquery: '../Scripts/libs/jquery-1.11.2',
    'jqueryui': '../Scripts/libs/jquery-ui',
    jscroll: '../Scripts/libs/jquery.jscroll', // and others

我在shim中没有看到任何关于jquerUI的提及:部分

您需要从项目中引用它。建议使用tsconfig,它可以形成编译上下文https://github.com/TypeStrong/atom-typescript/blob/master/docs/tsconfig.md

示例

{
    "compilerOptions": {
        "target": "es5",
        "module": "commonjs",
        "declaration": false,
        "noImplicitAny": false,
        "removeComments": true,
        "noLib": false
    },
    "filesGlob": [
        "./**/*.ts",
        "!./node_modules/**/*.ts"
    ],
    "files": [
        "./globals.ts",
        "./linter.ts",
        "./main/atom/atomUtils.ts",
        "./main/atom/autoCompleteProvider.ts",
        "./worker/messages.ts",
        "./worker/parent.ts",
        "./typings/jquery/jquery.d.ts",
    ]
}