P
Prismaโ€ข4d ago
Marius

Cannot import type in svelte component

Hi, I'm trying to use prisma-generated types in a Svelte (client side) component.
<script lang="ts">
import { TagType } from '@prisma/client';
import { cn } from '$lib/utils';

export let name;
export let type: TagType;
</script>

<!--apply tag color based on tagtype-->
<div class={cn("px-2 py-1", type === TagType.FIRE ? "red" : "blue")}>
<span>{name}</span>
</div>
<script lang="ts">
import { TagType } from '@prisma/client';
import { cn } from '$lib/utils';

export let name;
export let type: TagType;
</script>

<!--apply tag color based on tagtype-->
<div class={cn("px-2 py-1", type === TagType.FIRE ? "red" : "blue")}>
<span>{name}</span>
</div>
Is this possible in principle? I want to set the color depending on the value the prop type has. My browser console tells me TagType is undefined, but I don't get why. Vite doesn't report any errors. My IDE tells me that type === TagType.FIRE always returns null because there is no overlap. Can I solve this somehow? Thanks in advance!
4 Replies
Prisma AI Help
Prisma AI Helpโ€ข4d ago
You chose to debug with a human. They'll tinker with your query soon. If you get curious meanwhile, hop into #ask-ai for a quick spin!
Nurul
Nurulโ€ข4d ago
Hey ๐Ÿ‘‹ Does the solution specified in this GH Discussion work for you? https://github.com/prisma/prisma/discussions/14909
GitHub
Share Prisma types with frontend application? ยท prisma prisma ยท Dis...
Is it possible to share auto-generated TypeScript types with a front-end application?
Marius
MariusOPโ€ข4d ago
Thanks for the quick answer! I just saw https://github.com/prisma/prisma/issues/12504 which has a solution that works for me.
GitHub
Importing enum in browsers results in `Error resolving module spe...
Bug description I have the following error message in my browser upon using sveltekit and the command "npm run preview": Uncaught TypeError: Error resolving module specifier โ€œ.prisma/clie...
Nurul
Nurulโ€ข4d ago
I am glad to hear that ๐Ÿ™‚

Did you find this page helpful?