从 TypeScript 调用 JavaScript 类:Uncaught TypeError

我正在尝试在我的 TypeScript 包中为 Atom使用atom-select-list包中的普通 JavaScript 类(链接)。


我为此第 3 方依赖项添加了一个声明,并将其包含在我的包中,如下所示:


/// <reference path="../types/atom-select-list.d.ts"/>

import {SelectListView} from 'atom-select-list'; // copmiled to: `const atom_select_list_1 = require("atom-select-list");`

但是,我收到此错误


~\atom-indent-detective\dist\selector.js:11

Hide Stack Trace

TypeError: atom_select_list_1.SelectListView is not a constructor

    at Object.selector_show (~\atom-indent-detective\dist\selector.js:11:26)

    at HTMLElement.indentDetectiveChooseIndent (../lib/indent-detective.ts:1:12)

    at CommandRegistry.handleCommandEvent (~\atom-nightly\app-1.46.0-nightly8\resources\app\static\<embedded>:11:349292)

    at CommandRegistry.dispatch (~\atom-nightly\app-1.46.0-nightly8\resources\app\static\<embedded>:11:347767)

    at HTMLSpanElement.view.onclick (~\atom-indent-detective\dist\status.js:24:34)

这指向


indentListView = new SelectListView(...) //  compiled to `indentListView = new atom_select_list_1.SelectListView({...`

这是我的 tsconfig.json:


{

  "compilerOptions": {

    //// Linting Options - Uncomment options to get more features (usually more restrictive)

//        "strict": true, // includes all of the following and more

    "strictNullChecks": true,

    //    "forceConsistentCasingInFileNames": true,

    "noUnusedLocals": true,

    "noUnusedParameters": true,

    "noImplicitReturns": true,

    "noImplicitAny": true,

//    "noImplicitThis": true,

    "noFallthroughCasesInSwitch": true,

    "allowJs": true,


    //// Compilation options

    "declaration": true,

    "emitDecoratorMetadata": true,

    "esModuleInterop": true,

    "experimentalDecorators": true,

    "incremental": true,

    "inlineSourceMap": true,

//    "preserveConstEnums": true,

//    "sourceMap": true,

    "preserveSymlinks": true,

    "removeComments": true,

慕慕森
浏览 125回答 1
1回答

SMILET

我通过使用解决了这个问题:import&nbsp;SelectListView&nbsp;from&nbsp;'atom-select-list'或者const&nbsp;SelectListView&nbsp;=&nbsp;require('atom-select-list')
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript