<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Question Re: Error when using TypeScript with CAP in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/error-when-using-typescript-with-cap/qaa-p/12758374#M4789189</link>
    <description>&lt;P&gt;Btw this also works for me:&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;import * as cds from "@sap/cds"; &lt;BR /&gt;const { SELECT } = cds.ql&lt;BR /&gt;const sel = SELECT.from("Foo")&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 21 Jun 2023 09:19:21 GMT</pubDate>
    <dc:creator>former_member631165</dc:creator>
    <dc:date>2023-06-21T09:19:21Z</dc:date>
    <item>
      <title>Error when using TypeScript with CAP</title>
      <link>https://community.sap.com/t5/technology-q-a/error-when-using-typescript-with-cap/qaq-p/12758372</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
  &lt;P&gt;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 &lt;STRONG&gt;SELECT.from(table).where(…)&lt;/STRONG&gt; which of course TypeScript doesn’t like. I’m importing the types as per &lt;STRONG&gt;import { SELECT } from "@sap/cds/apis/ql"&lt;/STRONG&gt; . Now however, when I run my code with &lt;STRONG&gt;cds-ts watch&lt;/STRONG&gt; I receive this error &lt;STRONG&gt;Error: Cannot find module '@sap/cds/apis/ql'&lt;/STRONG&gt;. 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 &lt;STRONG&gt;cds/apis&lt;/STRONG&gt; work too, such as &lt;STRONG&gt;import { Service } from "@sap/cds/apis/services"&lt;/STRONG&gt; so it just seems to be the cql stuff that doesn’t work.&lt;/P&gt;
  &lt;P&gt;I can swap the import statement to&lt;/P&gt; 
  &lt;PRE&gt;&lt;CODE&gt;const cds = require("@sap/cds");
const { SELECT } = cds.ql;&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;which then allows me to run my service at least, but then I lose all TypeScript code help because SELECT becomes type 'any'.&lt;/P&gt;
  &lt;P&gt;So summarise:&lt;/P&gt; 
  &lt;PRE&gt;&lt;CODE&gt;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.
&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jun 2023 08:41:01 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/error-when-using-typescript-with-cap/qaq-p/12758372</guid>
      <dc:creator>johnmurray</dc:creator>
      <dc:date>2023-06-06T08:41:01Z</dc:date>
    </item>
    <item>
      <title>Re: Error when using TypeScript with CAP</title>
      <link>https://community.sap.com/t5/technology-q-a/error-when-using-typescript-with-cap/qaa-p/12758373#M4789188</link>
      <description>&lt;P&gt;Hi John,&lt;/P&gt;&lt;P&gt;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:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;const sel = SELECT.from(Foos).columns("x")
sel.from(Foo)
sel.columns("x")&amp;lt;br&amp;gt;&lt;/CODE&gt;&lt;/PRE&gt;
I will still look into the issue, that the code completion is missing, when using cds.ql.SELECT as type.</description>
      <pubDate>Tue, 20 Jun 2023 13:26:11 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/error-when-using-typescript-with-cap/qaa-p/12758373#M4789188</guid>
      <dc:creator>former_member631165</dc:creator>
      <dc:date>2023-06-20T13:26:11Z</dc:date>
    </item>
    <item>
      <title>Re: Error when using TypeScript with CAP</title>
      <link>https://community.sap.com/t5/technology-q-a/error-when-using-typescript-with-cap/qaa-p/12758374#M4789189</link>
      <description>&lt;P&gt;Btw this also works for me:&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;import * as cds from "@sap/cds"; &lt;BR /&gt;const { SELECT } = cds.ql&lt;BR /&gt;const sel = SELECT.from("Foo")&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 21 Jun 2023 09:19:21 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/error-when-using-typescript-with-cap/qaa-p/12758374#M4789189</guid>
      <dc:creator>former_member631165</dc:creator>
      <dc:date>2023-06-21T09:19:21Z</dc:date>
    </item>
  </channel>
</rss>

