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

后端 未结 3 1061
庸人自扰
庸人自扰 2020-12-08 09:32

I have an object where all the keys are string, some of the values are string and the rest are objects in this form:

var object = {
    \"fixedKey1\": \"some         


        
3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-08 09:53

    As @Paleo explained, you can use union property to define an interface for your corresponding object.

    I would say you should define an interface for object values and then you should define your original object.

    Sample interface can be:

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

提交回复
热议问题