Skip to content

Linting errors on schema from hub:db #748

@remihuigen

Description

@remihuigen

Describe the bug
Im running into issues with ESlint (mainly in CI context) when using import { db, schema } from 'hub:db'. It seems that schema is not properly typed in that context (though nuxi typecheck does pass)

Take the following example:

import { schema, db } from 'hub:db'
export default defineEventHandler(async (_event) => {
	const data = await db
		.select()
		.from(schema.exampleTable)
		.all()

	if (data.length > 0) {
		return data[0]
	}

	throw createError({ statusCode: 404, statusMessage: 'No data found' })

})

This would result in these linting errors

nuxt lint:   5:56  error  Unsafe member access .exampleTable on an `error` typed value                        @typescript-eslint/no-unsafe-member-access
nuxt lint:   9:15  error  Unsafe member access [0] on an `error` typed value                                  @typescript-eslint/no-unsafe-member-access

As soon as i start the development server (nuxt dev) the linting succeeds. However, this is not the case when running nuxt prepare, which is what happens in CI.

Steps to reproduce
Steps to reproduce the behavior:

  1. Setup Nuxt eslint module
  2. Create a schema
  3. import that schema and query it via a server route
  4. Setup linting in CI
  5. Run linting in CI

You should see errors like the one mentioned above

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions