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.

Low fidelity Typescript types for `context.query`

See original GitHub issue

Steps to reproduce

Follow the docs link to create a project: How to embed Keystone + SQLite in a Next.js app.

Expected result

It builds just fine, dynamic lists typings are connected with imports.

Actual result

npm run build doesn’t work:

image

List item types has any type (instead of Post for query.Post.findMany):

image

Node v14.18.1, macOS 12.1.

Workarounds

Currently I found out that it can be “fixed” by importing from .keystone/types and specifying types manually like this, for each usage on Next.js pages on frontend:

import { query } from '.keystone/api'
import { Lists } from '.keystone/types'

export async function getStaticProps() {
  const posts = (await query.Post.findMany({ query: 'id title slug' })) as Lists.Post.Item[]
  return { props: { posts } }
}

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
emmatowncommented, Feb 10, 2022

We’ve somewhat improved this with #7249 which is yet to be released and we’re looking at improving this further

1reaction
dmythrocommented, Jan 4, 2022

@dcousens thanks! Yes, complete typings implementation looks complicated for this kind of queries, but at least I’d expect this to return something like a Partial<Post> (or to be more precise, Promise<Partial<Post>>).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Context | React TypeScript Cheatsheets
Using createContext with an empty object as default value. ... // set the type of state you want to handle with context e.g....
Read more >
Prototyping and data modeling in the browser using TypeScript
The UX designers can review the low-fidelity UI rendered by React. The data model and the UI are two different views of the...
Read more >
Stripe API reference – Node
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries....
Read more >
DownloadManager - Android Developers
Query the download manager about downloads that have been requested. ... network and the download manager is waiting for a Wi-Fi connection to...
Read more >
Backbone.js
Remove a previously-bound callback function from an object. If no context is specified, all of the versions of the callback with different contexts...
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