The following code works well but I wish to rewrite it more clearly, with a Typescript idiom, if possible.
class Actions { actions: string[] }
type Argument = object | Actions;
export class GetFilesContext implements IExecutable {
execute( args: Argument, response: ServerResponse<IncomingMessage> ): void {
...
// eslint-disable-next-line no-prototype-builtins
if( args && args.hasOwnProperty( "actions" )) {
ctxt.actions.length = 0;
ctxt.actions.push( ...(args as Actions).actions );
}
response.end( JSON.stringify( ctxt ));
}
}
The two lines:
// eslint-disable-next-line no-prototype-builtins
if( args && args.hasOwnProperty( "actions" )) {
means "if args is defined and has an attribute actions"
How to write it?
I tried typeof and instanceof, without success.
The correct syntax was given by pink in comments, thanks!