Question: I am working on a Rest API in TypeScript.

The part I'm working on receives as a parameter a Type object containing a body attribute as being of type "Unknown".

I have to check that the body attribute that I received in my object as a parameter is strictly compliant with my Type / Interface, here in the exemple : "account"

And that's what I can't seem to do ...

[![enter image description here](https://i.stack.imgur.com/f1FoJ.png)](https://i.stack.imgur.com/f1FoJ.png)

[![enter image description here](https://i.stack.imgur.com/8GzMZ.png)](https://i.stack.imgur.com/8GzMZ.png)

Answer: 
You seem to want:

Your query can be radically simplified:

* The outer join is really an inner join due to the `WHERE` clause.
* The boolean conditions are much more complicated than necessary ( "(A OR B) AND A" is really just "A").
* No subquery is necessary.
* The `JOIN` conditions can be expanded.

So:

```
SELECT id.id, id.phone, id.business_name, id.address,
       arr.lc_compliant, arr_record.dnc_compliant
FROM import_data id JOIN
     api_request_record arr
     ON arr.company_id = id.company_id AND
        arr.data_record_id = id.id
WHERE id.company_id = 1 AND
      arr.dnc_compliant
ORDER BY id.phone DESC
LIMIT 100 OFFSET 600;

```

Then for this query, I would recommend the following indexes:

* `import_data(company_id, id)`
* `api_request_record(company_id, data_record_id, dnc_compliant)`

Note that these are indexes with multiple keys, not separate indexes on each key.
Try something like this

```
SELECT
    import_data.id,
    import_data.phone,
    import_data.business_name,
    import_data.address,
    api_request_record.lc_compliant,
    api_request_record.dnc_compliant
FROM
    import_data
    LEFT JOIN api_request_record on api_request_record.data_record_id = import_data.id AND (api_request_record.dnc_compliant = TRUE OR api_request_record.lc_compliant = TRUE)
WHERE
    import_data.company_id = 1
ORDER BY
    import_data.phone DESC
LIMIT 100 OFFSET 600;

```