Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

got TS2344 [ERROR]: Type does not satisfy the constraint 'Record<string, unknown>' using stmt.get #131

Open
YievCkim opened this issue Jul 23, 2024 · 2 comments

Comments

@YievCkim
Copy link

I have this table:

CREATE TABLE producers 
   ( id INT UNIQUE NOT NULL
   , title TEXT NOT NULL
   , phone TEXT NOT NULL
   , address TEXT NOT NULL
   , city TEXT NOT NULL
   , zip_code TEXT NOT NULL
   )

And this code produces a typescript error(TS2344):

interface ProducerRecord {
  id: number
  title: string
  phone: string
  address: string
  city: string
  zip_code: string
}

export function fetchProducer(id: number) {
  const stmt = db.prepare(
    'SELECT * FROM producers WHERE id=?;'
  )
  const datum = stmt.get<ProducerRecord>(id)
  if (datum) {
    return {
      ...datum,
      address: datum.address ? datum.address.split('\n') : []
    }
  }
  return null
}

This is the error I get:

error: TS2344 [ERROR]: Type 'ProducerRecord' does not satisfy the constraint 'Record<string, unknown>'.
  Index signature for type 'string' is missing in type 'ProducerRecord'.
  const datum = stmt.get<ProducerRecord>(id)

If I ignore this statement with:

  // @ts-ignore
  const datum = stmt.get<ProducerRecord>(id)

It works.

yet the documentation suggests that this is what is expected .

Did I miss something ?

@lil5
Copy link

lil5 commented Nov 16, 2024

The deno devs should be using

---get<T extends Record<string, unknown>>(
+++get<T extends Record<string, any>>(

@YievCkim
Copy link
Author

Ah yes... indeed. I am not an expert, but that makes sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants