TypeScript: Which type definition package to use?

TypeScript: Which type definition package to use?

KarloKarlo Posts: 34Questions: 10Answers: 0
edited February 2018 in Free community support

Hello!

I found (at least) two different type definition packages on https://www.npmjs.com
a) @types/datatables.net
b) @types/jquery.datatables

Both seem to be comprehensive on the first glance.

However
- a has other sub packages like @types/datatables.net-buttons
- For b the git repository link is broken (404)

So currently I'm using a.

What are your experiences?

Thanks
Karlo

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,431Questions: 1Answers: 10,048 Site admin
    Answer ✓

    Neither are official, in that they aren't published by myself. a) does look more complete through.

    Regards,
    Allan

  • jladburyjladbury Posts: 34Questions: 9Answers: 0

    I tried using a) to remove some TS2339 errors, but although some disappeared, some remained, and some new ones were introduced.
    I removed a) and got round the errors I originally had by replacing dot notation references with array literals (e.g. replacing $.fn.dataTable.Editor with $.fn["dataTable"].Editor, as suggested at ."https://stackoverflow.com/questions/38324949/error-ts2339-property-x-does-not-exist-on-type-y") .
    Any comments on this approach would be appreciated.

  • KarloKarlo Posts: 34Questions: 10Answers: 0

    I'm using a) with no problems, but in a few cases I had to add/merge some own definitions. What are the specific TS2339 errors that you see?

  • jladburyjladbury Posts: 34Questions: 9Answers: 0

    I was first prompted to install a) by this one:
    editor = new $.fn.dataTable.Editor({, which gave error Error:(64, 23) TS2339: Property 'dataTable' does not exist on type 'JQuery<HTMLElement>'.

    Installing a) removed it,. but introduced Error:(109, 13) TS2345: Argument of type '{ "dom": string; 'data': {}[]; 'columns': { 'title': string; 'data': string; }[]; 'columnDefs': (...' is not assignable to parameter of type 'Settings'. Object literal may only specify known properties, and '"select"' does not exist in type 'Settings'. when adding "select": 'single', to the DataTables setup parameters.

  • KarloKarlo Posts: 34Questions: 10Answers: 0

    I don't known about b), but for a). which is the npm package

    "@types/datatables.net": "1.10.8"

    I can e.g. write $.fn.dataTable.render.text() with no complains. I don't know about .Editor. My understanding is that this is a sepatate package, I don't known if there are type defs available that merge this in.

  • allanallan Posts: 61,431Questions: 1Answers: 10,048 Site admin

    As far as I am aware there aren't any typings for Editor yet I'm afraid.

    Allan

  • KarloKarlo Posts: 34Questions: 10Answers: 0

    So you may in this case either start your own typings project, or cast to <any> in your code:

    (<any>$.fn.dataTable).Editor({... or so

This discussion has been closed.