question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeScript load function example

See original GitHub issue

Describe the problem

It took me a long time to figure out how to write a TypeScript load function for __error.svelte

Describe the proposed solution

Include an example 😃

import type { ErrorLoadInput, LoadOutput } from "@sveltejs/kit";
export async function load({
  error,
  status,
}: ErrorLoadInput): Promise<LoadOutput> {
  return {
    props: {
      title: `${status}: ${error.message}`,
      stack: error.stack,
    },
  };
}

Alternatives considered

Don’t include an example 😦

Importance

nice to have

Additional Information

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:21 (9 by maintainers)

github_iconTop GitHub Comments

19reactions
JeanJPNMcommented, Oct 31, 2021

You can import the Load type:

import type { Load } from "@sveltejs/kit"

export const load: Load = ({ error, status }) => ({
  props: {
    title: `${status}: ${error.message}`,
    stack: error.stack,
  }
})

But I agree that there should be an example for this.

7reactions
frederikhorscommented, Mar 3, 2022

Yeah. It works but I think we should add some docs for Typescript. Not only for javascript.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeScript - Calling a Function - Tutorialspoint
TypeScript - Calling a Function, A function must be called so as to execute it. This process is termed as function invocation.
Read more >
Documentation - Modules - TypeScript
Modules import one another using a module loader. ... Any declaration (such as a variable, function, class, type alias, ... Some samples to...
Read more >
How To Use Functions in TypeScript - DigitalOcean
Creating Typed Functions​​ In this section, you will create functions in TypeScript, and then add type information to them. In this example, sum ......
Read more >
Importing functions in typescript - Stack Overflow
An example: // global.ts export function abc() { } // main.ts import { abc } from "./global" abc();. I suggest to read the...
Read more >
svelte kit load functions in typekit : r/sveltejs - Reddit
Wondering if I can add type definitions to my load function if at all possible? ... I built a MacOS Clone with TypeScript...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found