Skip to content

Using @cloudflare/worker-types for the app.d.ts #4898

Answered by colinhowells
jokull asked this question in Q&A
Discussion options

You must be logged in to vote

Edited to reflect current best practices

Hopefully this gives you a pointer to solving your case, this is what I'm doing at the moment:

// /src/app.d.ts
declare global {
	interface Window {
		someObnoxiousGlobalObjectFromAdVendor: any;
	}
	namespace App {
		interface Error {
			code?: string; // we always have 'message', but adding code
		}
		interface Locals {
			user?: import('$lib/types').User; // in case you have users
		}
		interface PageData {
			someDataYouLike?: import('$lib/types').LikedData; // $page.data.someDataYouLike
		}
		interface Platform {
			cf?: IncomingRequestCfProperties;
			env?: {
				CF_PAGES_COMMIT_SHA: string; // I use this for Kit version
				SOME_KV_BINDING: K…

Replies: 3 comments 4 replies

Comment options

You must be logged in to vote
1 reply
@jokull
Comment options

Answer selected by jokull
Comment options

You must be logged in to vote
1 reply
@colinhowells
Comment options

Comment options

You must be logged in to vote
2 replies
@jokull
Comment options

@axel-rock
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants