简体   繁体   中英

Define a typescript interface for an object that has dashes as the property name

I'd like to map

{
  "controller-element": { }
}

into an interface but because controller-element has a - I can't simply do

export interface IControllerResponse {
  controller-element: any;
}

Just enclose the field name in quotes:

export interface IControllerResponse {
  "controller-element": any;
}


const response: IControllerResponse={
    "controller-element": 123
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM