你如何在打字稿中使用jquery ui和commonjs

问题描述 投票:1回答:1

对于更多上下文,我决定将所有模块保持为commonjs格式以便于移植,并使用browserify和其他一些东西来捆绑前端的东西。

我使用TypeScript进行类型检查,但我不确定如何在我的配置中使用jquery ui。请参阅下面的简单示例。

的package.json

{
  "main": "Main.js",
  "license": "MIT",
  "dependencies": {
    "@types/jquery": "^2.0.34",
    "@types/jqueryui": "^1.11.31"
  }
}

tsconfig.json

{
  "compilerOptions": {
    "module": "commonjs",
    "baseUrl": ".",
    "allowSyntheticDefaultImports": true,
    "outDir": "build/js",
    "target": "es5",
    "sourceMap": true,
    "noImplicitAny": true,
    "typeRoots": ["./node_modules/@types/*"]
  }
}

Main.ts

'use strict';
import $ from 'jquery'

export class Main {
    constructor(public app: string) {
        $(() => {
            $('#date').datepicker();
        })

    }
}

我从typescript编译器得到的错误是Error:(7, 24) TS2339: Property 'datepicker' does not exist on type 'JQuery'.但是datepicker是在node_modules/@types/jqueryui/index.d.ts:1091中定义的。

所以我的问题是我如何使用在打字稿中工作的commonj来获取jquery ui。我试图避免使用三重斜杠指令(例如///<reverence path="..." />

javascript jquery jquery-ui typescript commonjs
1个回答
1
投票

试试这个:

import $ from "jquery";
declare var global: any
global.jQuery = $;
import "jqueryui";
© www.soinside.com 2019 - 2024. All rights reserved.