docs/marko-run/typescript.md
marko/run provides a global namespace MarkoRun with the following types:
MarkoRun.Handler - Type that represents a handler function to be exported by a +handler or +middleware file
MarkoRun.Route - Type of the route's params and metadata
MarkoRun.Context - Type of the request context object in a handler and $global in your Marko files. This type can be extended using TypeScript's module and interface merging by declaring a Context interface on the @marko/run module within your application code
declare module "@marko/run" {
interface Context {
customProperty: MyCustomThing; // will be globally defined on MarkoRun.Context
}
}
MarkoRun.Platform - Type of the platform object provided by the adapter in use. This interface can be extended in that same way as Context (see above) by declaring a Platform interface:
declare module "@marko/run" {
interface Platform {
customProperty: MyCustomThing; // will be globally defined on MarkoRun.Platform
}
}
If a TSConfig file is discovered in the project root, the Vite plugin will automatically generate a .d.ts file which provides more specific types for each of your middleware, handlers, layouts, and pages. This file will be generated at .marko-run/routes.d.ts whenever the project is built - including dev.
[!NOTE] TypeScript will not include this file by default. You should use the Marko VSCode plugin and add it in your tsconfig.
These types are replaced with more specific versions per routable file:
MarkoRun.Handler
MarkoRun.Route
MarkoRun.Context