Skip to content

server functions #12631

@huseeiin

Description

@huseeiin

Describe the problem

I'm always frustrated when i call an endpoint from client and all the typesafety goes away

<button
  on:click={async () => {
    const res = await fetch("/api/data");
    const data = await res.json();
    // const data: any
  }}>Get stuff</button
>

Describe the proposed solution

like astro, and solidstart, i want a feature that enables me to call server-side functions safely:

<script>
  // $lib/server/index.ts

  function getStuff() {
    return { hello: "world" };
  }

  import { getStuff } from "$lib/server";
</script>

<button
  on:click={() => {
    getStuff();
    // getStuff(): { hello: string; }
  }}>Get stuff</button
>

Alternatives considered

No response

Importance

would make my life easier

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions