on 06-06-2023 9:41 AM
Hi,
I've migrated one of my CAP projects to TypeScript and all is going well, however in my code I use quite a lot of SELECT.from(table).where(…) which of course TypeScript doesn’t like. I’m importing the types as per import { SELECT } from "@sap/cds/apis/ql" . Now however, when I run my code with cds-ts watch I receive this error Error: Cannot find module '@sap/cds/apis/ql'. Does anyone know how to resolve this? The file is there, and TypeScript is happy with types, so I’m at a loss as to what the problem is. Other imports from cds/apis work too, such as import { Service } from "@sap/cds/apis/services" so it just seems to be the cql stuff that doesn’t work.
I can swap the import statement to
const cds = require("@sap/cds");
const { SELECT } = cds.ql;
which then allows me to run my service at least, but then I lose all TypeScript code help because SELECT becomes type 'any'.
So summarise:
import { SELECT } from "@sap/cds/apis/ql"; // provides TypeScript code completion on SELECT,
// but cds-ts fails to run
const cds = require("@sap/cds"); // cds-ts runs, but TypeScript code completion is
const { SELECT } = cds.ql; // lost.
Thanks!
Hi John,
there is no need to require ql statements from cds, as they are globally defined, so code like this should work in TS without importing anything:
const sel = SELECT.from(Foos).columns("x")
sel.from(Foo)
sel.columns("x")<br>
I will still look into the issue, that the code completion is missing, when using cds.ql.SELECT as type.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Btw this also works for me:
import * as cds from "@sap/cds";
const { SELECT } = cds.ql
const sel = SELECT.from("Foo")
User | Count |
---|---|
72 | |
9 | |
8 | |
7 | |
6 | |
5 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.