TypeScript override existing package interface

226 Views Asked by At

How can I override existing interface property from package?

This is in the package:

   // in one file .d.ts
    export interface LDProps {
        flags?: LDFlagSet;
        ldClient?: LDClient;
    }

   // in other file .d.ts
    declare module 'module-name' {
       ...
       export interface LDFlagSet {
           [key: string]: LDFlagValue;
       }
       ...
    }

I want to override LDFlagSet properties. I do not want it to be key: string. I have my specific keys.

What I tried:

declare module 'module-name' {
    interface LDFlagSet {
        param1: boolean
    }
}

// obj.param1 should be valid
// obj.random should not be valid

Now my intellisense shows me that param1 exist with type boolean. But it allows me any other key: string with type any. I want only my properties to be valid.

How I can do that?

0

There are 0 best solutions below