Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

typescript

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;
}
like image 414
Archimedes Trajano Avatar asked Oct 30 '25 09:10

Archimedes Trajano


1 Answers

Just enclose the field name in quotes:

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


const response: IControllerResponse={
    "controller-element": 123
}
like image 120
Mario Vernari Avatar answered Oct 31 '25 23:10

Mario Vernari