0

I'm trying to add the e.g. responsive property into e.g. interface Settings from e.g. node_modules/@types/datatables.net/index.d.ts:

declare namespace DataTables {
    ...
    interface Settings {
    ...

My project is based on https://github.com/gdi2290/angular-starter and I want to use that property with datatables.net-responsive-bs4 which implements it.

Q: How would I write the declaration for adding the responsive property?

PS: I'm specifically interesting in learning how to write that kind of declaration into my project

1 Answer 1

1

There is a difference between augmenting a module and an ambient declaration. In your case the definitions for datatables.net just de declare a namespace and an interface. This means you can just redeclare these in another d.ts file and they will get merged:

// datatables.d.ts
declare namespace DataTables {

    interface Settings {
        responsive : boolean
    }
}

// usage.ts
/// <reference path="./node_modules/@types/datatables.net/index.d.ts" />
/// <reference path="./datatables.d.ts" />

let settings : DataTables.Settings = {
    responsive: true, // ok, from us 
    autoWidth: true // from lib
}

For module augmentation you can have a look here in the module augmentation section.

PS: tslint.json should use at least "allow-declarations" for the rule "no-namespace" otherwise the IDE might trick you by invalidating the declare keyword (e.g. use "no-namespace": [true, "allow-declarations"]).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.