typescript interface definition with an unknown property key

后端 未结 3 415
终归单人心
终归单人心 2021-01-11 14:09

How to express an interface (IResponse), with one property has a string key (which is not known statically). Below, the key values can be anything like bo

3条回答
  •  太阳男子
    2021-01-11 14:48

    Old question, but here is how I solved the issue for myself.

    export interface Foo {
        [key: string]: any;
    }
    
    { something: 0 } as Foo => valid
    
    { other: 'hello' } as Foo => valid
    

提交回复
热议问题