cap-js / cds-types

Type definitions for CDS
Apache License 2.0
9 stars 8 forks source link

[BUG] Cannot use a 'where' statement on a projection used in SELECT.from(...).columns() #203

Open mutschosW opened 4 weeks ago

mutschosW commented 4 weeks ago

Is there an existing issue for this?

Current Behavior

I use the projection syntax in a SELECT to expand associations. Unfortunately, the proposed solution at the CAP documentation (combination of projection and tagged template strings) is not valid TypeScript syntax. Here the example from the documentation:

SELECT.from ('Authors', a => {
   a.ID, a.name, a.books (b => {
     b`.*`, 
     b.suppliers`[city='Paris']`('*')
   })
})

I tried a workaround which is working:

SELECT.from ('Authors', (a) => [
   a.ID, a.name, a.books ((b) => [
     b('.*'), 
     (b.suppliers((s) => [s('*')]) as SELECT<unknown>).where(`city = 'Paris'`)
  ])
])

but unfortunately a cast to SELECT<unknown> is necessary.

Expected Behavior

The expected behaviour is allowing the "where" w/o casting:

SELECT.from ('Authors', (a) => [
   a.ID, a.name, a.books ((b) => [
     b('.*'), 
     b.suppliers((s) => [s('*')]).where(`city = 'Paris'`)
  ])
])

References

https://cap.cloud.sap/docs/node.js/cds-ql#columns

Versions

Package Version
Node.js v20.11.0
@sap/cds 7.9.2
@sap/cds-compiler 4.9.4
@sap/cds-dk 7.9.2
@sap/cds-dk (global) 7.6.0
@sap/eslint-plugin-cds 3.0.3
@sap/cds-mtxs 1.18.0
@cap-js/cds-types 0.2.0

Anything else? Logs?

I can also contribute if you need.