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

fix: update type generic to allow interfaces #141

Merged
merged 1 commit into from
Dec 18, 2024

Conversation

chaucerbao
Copy link
Contributor

The definition of the type-generic used on the sql() function is:

sql<T extends Record<string, unknown> = Record<string, any>>

The Record<string, unknown> is an alias for the { [key: string]: unknown } type signature. The problem is that interface definitions don't include this type signature, so they cannot be passed into this type-generic.

Here's a standalone example:

interface MyInterface {
  name: string
}

const myFunc = <T extends Record<string, unknown> = Record<string, any>>(
  param: T,
) => undefined

const myInterface: MyInterface = {
  name: 'Name',
}

myFunc<MyInterface>(myInterface)

This will produce a type-check error:

Type 'MyInterface' does not satisfy the constraint 'Record<string, unknown>'.
Index signature for type 'string' is missing in type 'MyInterface'. [2344]

Copy link
Member

@DjDeveloperr DjDeveloperr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for the fix!

@DjDeveloperr DjDeveloperr merged commit c078d61 into denodrivers:main Dec 18, 2024
4 of 5 checks passed
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

Successfully merging this pull request may close these issues.

2 participants