【问题标题】:How to use JQuery.Datatable extensions with Typescript?: Not Assignable to parameter of type 'Settings'如何将 JQuery.Datatable 扩展与 Typescript 一起使用?:不可分配给“设置”类型的参数
【发布时间】:2018-05-26 10:38:42
【问题描述】:

我看到this solution for a similar 问题,但在我的项目中找不到旧的 JQuery.Datatable 类型文件的证据,所以我不知道我的问题来自哪里。我使用的是 npm,而不是 Nuget。我不知道是否有另一种方式我应该引用该类型,或者.DataTable({responsive: true}) 调用的参数是否有不同的语法。

Error   TS2345  (TS) Argument of type '{ responsive: boolean; }' is not assignable to parameter of type 'Settings'.
  Object literal may only specify known properties, and 'responsive' does not exist in type 'Settings'.

package.json:

 "devDependencies": {
    "@types/datatables.net": "^1.10.8",
    "@types/jquery": "^3.2.16",
    "@types/knockout": "^3.4.46",
    "@types/knockout.mapping": "^2.0.30",
    "@types/knockout.validation": "0.0.35",
    "@types/requirejs": "^2.1.31",
    "@types/underscore": "^1.8.5",
    "css-loader": "^0.28.7",
    "datatables-bootstrap3-plugin": "0.5.0",
    "datatables-epresponsive": "0.0.3",
    "datatables.net": "^1.10.16",
    "datatables.net-dt": "^1.10.16",

fooViewModel.ts

    import * as ko from "knockout"
    import * as $ from "jquery"
    import "datatables.net";
    import "datatables-epresponsive";
    import "datatables.net-dt"; 


export class FooViewModel {

        constructor() {
            super();
            this.instantiateLocalObjects();

            if (this.containerIsLoaded()) {
                this.onPageIsActive();

                $("#employeeTable").DataTable({ responsive: true } ); 
            }
        }

更新:似乎问题是特定于尝试使用 JQuery.Datatable 扩展(例如响应式和选择)。例如 这不会引发任何错误:

$("#employeeTable").DataTable({
                "paging": false,
                "ordering": false,
                "info": false } );

【问题讨论】:

    标签: visual-studio typescript datatables typescript-typings


    【解决方案1】:

    问题是实际上每个扩展都有类型文件我安装了datatables-epresponsive,以为是datatables-responsive

    我不得不跑:

    npm install --save datatables.responsive.typings
    npm install datatables.net-responsive
    

    我也尝试使用 select 并且需要这个:

    npm install --save @types/datatables.net-select
    

    【讨论】:

    • 部分工作,仍然收到警报row is not a Method...,但解决了约 90% 的问题
    猜你喜欢
    • 2020-06-18
    • 2023-03-15
    • 2021-10-17
    • 2020-03-26
    • 2020-07-14
    • 2022-06-24
    • 1970-01-01
    • 2019-01-03
    • 2023-01-18
    相关资源
    最近更新 更多