I have an interface [simplified]
export default interface FormListarAtendimentosDTO {
idArea?: number;
idAssunto?: number;
idMotivo?: number;
order?: string;
page?: number;
pageSize?: number;
}
I have an instantiated query object with:
let form:FormListarAtendimentosDTO = { order: "ASC", page: 1, pageSize: 10 }
I have an updateQuery object with
let updateQuery = {queryParam: "idArea", value:"10"}
I want to check if obj.queryParam is a valid key on FormListarAtendimentosDTO, so I can update form to include the value on updateQuery. How do I do that?
if(keyExistsInInterface("idArea", FormListarAtendimentosDTO ))
{
form.idArea = value
}
I tried to use
form.hasOwnProperty("idArea") and got false, because the value wasn't initialized
form.hasOwnProperty(updateQuery.queryParam) (same thing)
I tried
type K = keyof FormListarAtendimentosDTO
but i’m don’t know how to use this information.
I tried
if("idArea" in formListarAtendimentosDTO)
didn’t work either, always returned false
Asderek is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1