0

I'm working with angular-gridster2, which has an interface, GridsterConfig:

export interface GridsterConfig {
    fixedColWidth?: number;
    fixedRowHeight?: number;
...
    [propName: string]: any;
}

The problem is, the propName allows any property to be added or referenced, allowing for typos to be ignored by the compiler. This compiles just fine:

let foo: GridsterConfig = {};
foo.doesnotexist = "OOPS";

I know that I can create a new interface with Pick:

type MyGridsterConfig1 = Pick<GridsterConfig, 'fixedColWidth' | 'fixedRowHeight'>;
let mgc1: MyGridsterConfig1 = {};
mgc1.doesnotexist = 100;  // <-- compiler error

And can use Omit on explicit properties, but I haven't found a way to effectively do:

Omit<GridsterConfig, '[propName: string]'>.  

The only thing I've found so far is to Pick all the properties (there's a number of them). Is there a better way to do this?

mconner
  • 1,174
  • 3
  • 12
  • 24
  • 3
    Does this answer your question? [TypeScript: remove index signature using mapped types](https://stackoverflow.com/questions/51465182/typescript-remove-index-signature-using-mapped-types) – bugs Mar 20 '20 at 16:56
  • @bugs: Yes, that's what I was looking for. There's no way I'd ever have come up with that (though I wonder how I missed it in my search). – mconner Mar 20 '20 at 17:44
  • @bugs: Do you want to add that as an answer? – mconner Mar 24 '20 at 16:01

0 Answers0