Typescript types with Bootstrap variants

Typescript types with Bootstrap variants

geometrygeometry Posts: 20Questions: 5Answers: 0

We have started to use the internal Typescript type definitions provided with DataTables but have run into some issues specifically with the Bootstrap variants

Both datatables.net and datatables.net-bs export a Config type but yet all the -bs plugin variants seem to extend the non -bs Config? Is this correct? Should we be just using the Config type from the core datatables.net and ignore the one from datatables.net-bs

Hopefully that makes sense

Answers

  • allanallan Posts: 58,873Questions: 1Answers: 9,472 Site admin

    Is this correct?

    Yes. The datatables.net package is the core package and is a dependency of datatables.net-bs. The -bs (and other styling packages) just set a bunch of default parameters on the DataTable object in order to make the theming suitable for the styling framework.

    The styling packages just re-export the core file.

    Generally you should just import the style package - since the core file is a dependency, there is no need to import it directly - e.g.:

    import DataTable from 'datatables.net-bs5';
    import 'datatables.net-buttons-bs5';
    

    Rather than:

    import DataTable from 'datatables.net';
    import 'datatables.net-bs5';
    import 'datatables.net-buttons';
    import 'datatables.net-buttons-bs5';
    

    It is basically exactly the same - the first just more compact :)

    Allan

  • geometrygeometry Posts: 20Questions: 5Answers: 0

    Ok so what you're saying is that I should just use the types from the -bs variants only and that makes sense to me but we are seeing errors like this

    And this one isn't the only plugin with strange errors. The responsive one also shows this when using the Config type from the the -bs version
    e.g import { Config } from "datatables.net-bs"

  • allanallan Posts: 58,873Questions: 1Answers: 9,472 Site admin
    edited May 29

    Scrap that. I was thinking the extension hadn't been imported, but I see it has. Looking into it more...

  • allanallan Posts: 58,873Questions: 1Answers: 9,472 Site admin

    Right I see the error. The styling packages are incorrectly including their own copy of the DataTables core type information. So when a package such as Select extends DataTables core, it does the core, but not the styling package. The styling package should inherit from the core, so it would also be extended.

    I need to change our build process to fix this - apologies.

    Allan

  • geometrygeometry Posts: 20Questions: 5Answers: 0

    No worries @allan. Thanks for the follow up and the confirmation we weren't on the wrong track. We'll keep our eyes open for an update :smile:

Sign In or Register to comment.