question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Question: "Cannot find namespace 'e' when using Typescript types from edgeql-js

See original GitHub issue

Hi! Sorry for a “question issue”, but I just can’t get past this myself.

  • I’ve setup edgeql-js according to the docs.
  • I’ve run npx edgeql-js to generate all code.
  • I can query for results with e.select().run(client) and so on.

But when I try to do use a generated TS type from the package, I run into this TS error:

error TS2503: Cannot find namespace 'e'

Code:

import e from './edgeql-js'; // auto-generated

// can't use my own types from the schema:
//   error TS2503: Cannot find namespace 'e'
let c: e.Contact = {};

// not even built-types work:
//   error TS2503: Cannot find namespace 'e'
let s: e.str = e.str('hey');

I’m following the docs in “Objects and paths”, which says:

All object types in your schema are reflected into the query builder, properly namespaced by module. … For convenience, the contents of the default module are also available at the top-level of e.

Are the docs talking about the Typescript type here? Or is it a reference to the EdgeQL schema type?

Thoughts

  • Am I somehow misunderstanding the use of the types from edgeql-js? Am I not supposed to be using them like this? I was of the impression of that I could generate TS types and use in my app code. I understand the types are inferred when returning from a query function, but there are places where I’d like to get hold of the type too, for use in React component props, for instance.
  • Am I importing e incorrectly?

Versions

Typescript: 4.5.5
EdgeDB (npm): 0.19.8

Many thanks!

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
jaclarkecommented, Mar 2, 2022
0reactions
colinhackscommented, Mar 1, 2022

The $XXXXXλShape types are very different - that is a complex data structure representing that EdgeDB type. You can introspect what this type looks like by playing around with autocompletion:

e.Movie.__element__.__pointers__;
// $MovieλShape
Screen Shot 2022-03-01 at 2 59 49 PM

We don’t currently generate “plain” types like what you are describing, though I think we should. It’ll probably look something like this:

import e, {types} from "./dbschema/edgeql-js";
type Movie = types["default"]["Movie"];
// {title: string; actors: Person, ...}

Should be possible to do @jaclarke thoughts? Internally it’ll look something like this:

interface default$$User {
  name: string;
  filmography: default$$Movie[];
}
interface default$$Movie {
  name: string;
  actors: default$$User[];
}
interface default$$ {
  User: default$$User;
  Movie: default$$Movie;
}
export interface types {
  default: default$$;
}

type asdf = types['default']['User']['filmography']
Read more comments on GitHub >

github_iconTop Results From Across the Web

Typescript: Cannot find namespace - Stack Overflow
This causes a Typescript error on express() of Cannot invoke an expression whose type lacks a call signature. Type 'typeof e' has no...
Read more >
AllowJs - ts-check - Cannot find namespace #19547 - GitHub
In my hypothetical example demo won't be globally available. How would it be possible to import types from that thirdParty plugin into a...
Read more >
tslint error "Cannot find namespace 'MicrosoftGraph'. ts(2503 ...
I followed all the instructions npm install @microsoft/microsoft-graph-client --save npm install @microsoft/microsoft-graph-types --save-dev.
Read more >
Cannot find namespace Context error in React (TypeScript)
To solve the "Cannot find name context" error in React typescript, use a `.tsx` extension for the files in which you use JSX,...
Read more >
edge-js - npm
There are 53 other projects in the npm registry using edge-js. ... TypeScript icon, indicating that this package has built-in type declarations.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found