.row.add().draw().node(); in TS gives "TS2339: Property 'node' does not exist on type 'Api'

.row.add().draw().node(); in TS gives "TS2339: Property 'node' does not exist on type 'Api'

alexNZalexNZ Posts: 2Questions: 1Answers: 0
edited March 2023 in Free community support

We're trying to convert our codebase from JS to Typescript. I've been able to solve almost all of the complication issues however this has left me stumped:

It's functionally the same as the example from row.add()

import "datatables.net-dt";
import "datatables.net-select-dt";

let table = $('#example').DataTable();

let rowNode = table
    .row.add( [ 'Fiona White', 32, 'Edinburgh' ] )
    .draw()
    .node();

$( rowNode )
    .css( 'color', 'red' )
    .animate( { color: 'black' } );

This also does not compile for me. Typescript does not seem to be missing anything, the draw function returns Api<any[][]> which does not possess the function node().

Am I missing an import? Is this simply not possible in Typescript? If so what are my alternatives?

Thanks

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 62,099Questions: 1Answers: 10,183 Site admin

    It doesn't. DataTables doesn't have a top level node() method. I think our example is technically wrong there - my apologies! I'll sort that out.

    What you need to do is:

    let rowNode = table.row.add(...).node();
    table.draw();
    

    Allan

  • alexNZalexNZ Posts: 2Questions: 1Answers: 0

    Thanks for the speedy response. I don't think your example works in ts either, because add() also returns an Api object. Is the right move (for now) to look in the table for the added row, and call node() on that?

  • allanallan Posts: 62,099Questions: 1Answers: 10,183 Site admin
    edited March 2023 Answer ✓

    Probably. Sorry about that. It looks like the error is here. That should be replying with an extended ApiRowMethods. Bug filed in our tracker :)

    Allan

Sign In or Register to comment.