Quantcast
Channel: Active questions tagged svelte - Stack Overflow
Viewing all articles
Browse latest Browse all 1546

How to strongly type the response of SvelteKit endpoint in the component?

$
0
0

So it looks like I have to separately type the response body going out of an endpoint and the props that I get from that body in the component. For example:

// index.ts (endpoint)import type { RequestHandler } from "./__types";export const get: RequestHandler<{  foo: number;  bar: string;}> = () => {  return {    body: {      foo: 42,      bar: "hello"    }  };};
// index.svelte (component)<script lang="ts">  export let foo;  // Not typed?  export let bar;</script>

I guess my question is why am I typing the response going out if I don't benefit from that typing in the component props?


Viewing all articles
Browse latest Browse all 1546

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>