Typescript interface for objects with some known and some unknown property names

export interface IfcObjectValues {
    param1: number[];
    param2: string;
    param3: string;        
}

interface MyInterface {
  fixedKey1: string,
  fixedKey2: number,
  [x: string]: IfcObjectValues, 
}

Your code in action, see here.


It's not exactly what you want, but you can use a union type:

interface IfcObject {
    fixedKey1: string
    fixedKey2: string
    [key: string]: string | {
        param1: number[];
        param2: string; 
        param3: string;
    }
}

It covers your case. But the unknown properties could be of type string.

Tags:

Typescript