0

I have an interface with 2 fields: featureName, which is a string, and another request, which is an object {}.

export interface SocketsRequest {
  featureName: string;
  request: {};
}

Because I want that request field to have a required field actionType, I updated the interface and it became:

 export interface SocketsRequest {
  featureName: string;
  request: {actionType: string}; // how I can let many other fields here?
 }

But now, the problem is that request object must have only one field: actionType. Else, I'll get an error for incompatible types:

const request: SocketsRequest = {
  featureName: 'orders',
  request: {
    actionType: 'all',
    country: 'DE' // country can not be a part of request object
  }
}

How can be this solved? thx

AlleXyS
  • 2,476
  • 2
  • 17
  • 37
  • Do you mean `actionType` is optional field in `request`? – Ninad Jan 11 '22 at 13:34
  • `actionType` is required, the rest are optionals (dynamically builded). Somebody shown a solution from another question and marked this as duplicated. thx – AlleXyS Jan 11 '22 at 13:35

0 Answers0