#Help avoiding an ESLint error of "assigned a value but only used as a type"

12 messages · Page 1 of 1 (latest)

lost tartan
#

I am using the following code to create a custom Prisma type:

    include: { student: true }
});

export type SgWithStudent = Prisma.StudentGuardianGetPayload<
    ReturnType<() => typeof sgWithStudent>
>;```

The proble is ESLint is flagging this as `'sgWithStudent' is assigned a value but only used as a type.(@typescript-eslint/ no-unused-vars)`. I don't want to disable all unused var checking.. Is there a way I can re write this that won't trigger the warning?
obtuse dagger
#

@lost tartan could you make a playground with your code? i'm not a prisma user and i don't know what to import for that Prisma namespace

#

hmm, their docs say import { Prisma } from '@prisma/client' but that's not working for me

lost tartan
#

It won't work in ts playground for some reason. The ESLint problem can be demonstrated using non Prisma though..

const foo = someFunction()
type bar = ReturnType< () => typeof foo >

ESLint: 'foo' is assigned a value but only used as a type.(@typescript-eslint/ no-unused-vars)

obtuse dagger
#

yeah that's not helpful here though. i was going to help figure out how to refer to that type without writing a function (which is definitely possible. i don't think there's ever a case where you need to introduce a value like that)

sonic mango
obtuse dagger
#

ah, yeah that tracks

sonic mango
#

But yeah, @lost tartan you can // eslint-disable-next-line @typescript-eslint/ no-unused-vars on the appriate line - though I do agree that making a runtime validator and then not using it and only generating a type from it feels roundabout and something that you could avoid

#

But if you're going to use the validator anyway eventually you may as well just ignore the issue.

#

(Actually exporting the validator would probably make it go away)

lost tartan
#

Why does exporting solve the problem?