Typescript object indexer and key that doesn't match indexer type

前端 未结 2 1033
灰色年华
灰色年华 2021-01-20 18:34

The Typescript docs show the following example:

interface NumberDictionary {
    [index: string]: number;
    length: number;    // ok, length is a number
           


        
2条回答
  •  囚心锁ツ
    2021-01-20 19:21

    Like this:

    interface NumberDictionary {
        [index: string]: number | string;
        length: number;
        name: string;
    }
    

提交回复
热议问题