From d552ac16fd028a02a042e388e87e264db692dbd9 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Thu, 19 Jan 2023 11:30:47 -0500 Subject: [PATCH] chore: use `declare global` instead of ambient declarations (#8589) closes #8587 --- .../60-adapter-cloudflare.md | 16 +++++++++------ .../70-adapter-cloudflare-workers.md | 16 +++++++++------ documentation/docs/30-advanced/20-hooks.md | 12 +++++++---- documentation/docs/30-advanced/25-errors.md | 14 ++++++++----- .../adapter-static/test/apps/spa/src/app.d.ts | 3 --- packages/kit/test/apps/basics/src/app.d.ts | 20 +++++++++++-------- packages/kit/test/apps/options-2/src/app.d.ts | 1 - .../kit/test/apps/options/source/app.d.ts | 7 ------- packages/kit/test/apps/writes/src/app.d.ts | 7 ------- .../src/app.d.ts | 7 ------- .../apps/private-dynamic-env/src/app.d.ts | 7 ------- .../src/app.d.ts | 7 ------- .../apps/private-static-env/src/app.d.ts | 7 ------- .../src/app.d.ts | 7 ------- .../apps/server-only-folder/src/app.d.ts | 7 ------- .../src/app.d.ts | 7 ------- .../apps/server-only-module/src/app.d.ts | 7 ------- 17 files changed, 49 insertions(+), 103 deletions(-) delete mode 100644 packages/adapter-static/test/apps/spa/src/app.d.ts delete mode 100644 packages/kit/test/apps/options-2/src/app.d.ts delete mode 100644 packages/kit/test/apps/options/source/app.d.ts delete mode 100644 packages/kit/test/apps/writes/src/app.d.ts delete mode 100644 packages/kit/test/build-errors/apps/private-dynamic-env-dynamic-import/src/app.d.ts delete mode 100644 packages/kit/test/build-errors/apps/private-dynamic-env/src/app.d.ts delete mode 100644 packages/kit/test/build-errors/apps/private-static-env-dynamic-import/src/app.d.ts delete mode 100644 packages/kit/test/build-errors/apps/private-static-env/src/app.d.ts delete mode 100644 packages/kit/test/build-errors/apps/server-only-folder-dynamic-import/src/app.d.ts delete mode 100644 packages/kit/test/build-errors/apps/server-only-folder/src/app.d.ts delete mode 100644 packages/kit/test/build-errors/apps/server-only-module-dynamic-import/src/app.d.ts delete mode 100644 packages/kit/test/build-errors/apps/server-only-module/src/app.d.ts diff --git a/documentation/docs/25-build-and-deploy/60-adapter-cloudflare.md b/documentation/docs/25-build-and-deploy/60-adapter-cloudflare.md index c3c9d5b451fa..50409446f7ea 100644 --- a/documentation/docs/25-build-and-deploy/60-adapter-cloudflare.md +++ b/documentation/docs/25-build-and-deploy/60-adapter-cloudflare.md @@ -59,14 +59,18 @@ To make these types available to your app, reference them in your `src/app.d.ts` ```diff /// file: src/app.d.ts -declare namespace App { - interface Platform { -+ env?: { -+ YOUR_KV_NAMESPACE: KVNamespace; -+ YOUR_DURABLE_OBJECT_NAMESPACE: DurableObjectNamespace; -+ }; +declare global { + namespace App { + interface Platform { ++ env?: { ++ YOUR_KV_NAMESPACE: KVNamespace; ++ YOUR_DURABLE_OBJECT_NAMESPACE: DurableObjectNamespace; ++ }; + } } } + +export {}; ``` > `platform.env` is only available in the production build. Use [wrangler](https://developers.cloudflare.com/workers/cli-wrangler) to test it locally diff --git a/documentation/docs/25-build-and-deploy/70-adapter-cloudflare-workers.md b/documentation/docs/25-build-and-deploy/70-adapter-cloudflare-workers.md index ad3ada052f78..4049302d6270 100644 --- a/documentation/docs/25-build-and-deploy/70-adapter-cloudflare-workers.md +++ b/documentation/docs/25-build-and-deploy/70-adapter-cloudflare-workers.md @@ -94,14 +94,18 @@ To make these types available to your app, reference them in your `src/app.d.ts` ```diff /// file: src/app.d.ts -declare namespace App { - interface Platform { -+ env?: { -+ YOUR_KV_NAMESPACE: KVNamespace; -+ YOUR_DURABLE_OBJECT_NAMESPACE: DurableObjectNamespace; -+ }; +declare global { + namespace App { + interface Platform { ++ env?: { ++ YOUR_KV_NAMESPACE: KVNamespace; ++ YOUR_DURABLE_OBJECT_NAMESPACE: DurableObjectNamespace; ++ }; + } } } + +export {}; ``` > `platform.env` is only available in the production build. Use [wrangler](https://developers.cloudflare.com/workers/cli-wrangler) to test it locally diff --git a/documentation/docs/30-advanced/20-hooks.md b/documentation/docs/30-advanced/20-hooks.md index 63f4addddd5d..6c3f5a1a3627 100644 --- a/documentation/docs/30-advanced/20-hooks.md +++ b/documentation/docs/30-advanced/20-hooks.md @@ -148,12 +148,16 @@ The following code shows an example of typing the error shape as `{ message: str ```ts /// file: src/app.d.ts -declare namespace App { - interface Error { - message: string; - errorId: string; +declare global { + namespace App { + interface Error { + message: string; + errorId: string; + } } } + +export {}; ``` ```js diff --git a/documentation/docs/30-advanced/25-errors.md b/documentation/docs/30-advanced/25-errors.md index 24d4862f618f..9932fa0b891f 100644 --- a/documentation/docs/30-advanced/25-errors.md +++ b/documentation/docs/30-advanced/25-errors.md @@ -139,14 +139,18 @@ The exception is when the error occurs inside the root `+layout.js` or `+layout. If you're using TypeScript and need to customize the shape of errors, you can do so by declaring an `App.Error` interface in your app (by convention, in `src/app.d.ts`, though it can live anywhere that TypeScript can 'see'): -```ts +```diff /// file: src/app.d.ts -declare namespace App { - interface Error { - code: string; - id: string; +declare global { + namespace App { + interface Error { ++ code: string; ++ id: string; + } } } + +export {}; ``` This interface always includes a `message: string` property. diff --git a/packages/adapter-static/test/apps/spa/src/app.d.ts b/packages/adapter-static/test/apps/spa/src/app.d.ts deleted file mode 100644 index 779a3d4e5104..000000000000 --- a/packages/adapter-static/test/apps/spa/src/app.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// - -declare namespace App {} diff --git a/packages/kit/test/apps/basics/src/app.d.ts b/packages/kit/test/apps/basics/src/app.d.ts index 15ac25fc1abc..b0b67f6fff90 100644 --- a/packages/kit/test/apps/basics/src/app.d.ts +++ b/packages/kit/test/apps/basics/src/app.d.ts @@ -1,10 +1,14 @@ -declare namespace App { - interface Locals { - answer: number; - name?: string; - key: string; - params: Record; - } +declare global { + namespace App { + interface Locals { + answer: number; + name?: string; + key: string; + params: Record; + } - interface Platform {} + interface Platform {} + } } + +export {}; diff --git a/packages/kit/test/apps/options-2/src/app.d.ts b/packages/kit/test/apps/options-2/src/app.d.ts deleted file mode 100644 index 63908c66cfd4..000000000000 --- a/packages/kit/test/apps/options-2/src/app.d.ts +++ /dev/null @@ -1 +0,0 @@ -/// diff --git a/packages/kit/test/apps/options/source/app.d.ts b/packages/kit/test/apps/options/source/app.d.ts deleted file mode 100644 index f691327e92ad..000000000000 --- a/packages/kit/test/apps/options/source/app.d.ts +++ /dev/null @@ -1,7 +0,0 @@ -/// - -declare namespace App { - interface Locals {} - - interface Platform {} -} diff --git a/packages/kit/test/apps/writes/src/app.d.ts b/packages/kit/test/apps/writes/src/app.d.ts deleted file mode 100644 index f691327e92ad..000000000000 --- a/packages/kit/test/apps/writes/src/app.d.ts +++ /dev/null @@ -1,7 +0,0 @@ -/// - -declare namespace App { - interface Locals {} - - interface Platform {} -} diff --git a/packages/kit/test/build-errors/apps/private-dynamic-env-dynamic-import/src/app.d.ts b/packages/kit/test/build-errors/apps/private-dynamic-env-dynamic-import/src/app.d.ts deleted file mode 100644 index 917a963999f3..000000000000 --- a/packages/kit/test/build-errors/apps/private-dynamic-env-dynamic-import/src/app.d.ts +++ /dev/null @@ -1,7 +0,0 @@ -// See https://kit.svelte.dev/docs/types#app -// for information about these interfaces -// and what to do when importing types -declare namespace App { - // interface Locals {} - // interface Platform {} -} diff --git a/packages/kit/test/build-errors/apps/private-dynamic-env/src/app.d.ts b/packages/kit/test/build-errors/apps/private-dynamic-env/src/app.d.ts deleted file mode 100644 index 917a963999f3..000000000000 --- a/packages/kit/test/build-errors/apps/private-dynamic-env/src/app.d.ts +++ /dev/null @@ -1,7 +0,0 @@ -// See https://kit.svelte.dev/docs/types#app -// for information about these interfaces -// and what to do when importing types -declare namespace App { - // interface Locals {} - // interface Platform {} -} diff --git a/packages/kit/test/build-errors/apps/private-static-env-dynamic-import/src/app.d.ts b/packages/kit/test/build-errors/apps/private-static-env-dynamic-import/src/app.d.ts deleted file mode 100644 index 917a963999f3..000000000000 --- a/packages/kit/test/build-errors/apps/private-static-env-dynamic-import/src/app.d.ts +++ /dev/null @@ -1,7 +0,0 @@ -// See https://kit.svelte.dev/docs/types#app -// for information about these interfaces -// and what to do when importing types -declare namespace App { - // interface Locals {} - // interface Platform {} -} diff --git a/packages/kit/test/build-errors/apps/private-static-env/src/app.d.ts b/packages/kit/test/build-errors/apps/private-static-env/src/app.d.ts deleted file mode 100644 index 917a963999f3..000000000000 --- a/packages/kit/test/build-errors/apps/private-static-env/src/app.d.ts +++ /dev/null @@ -1,7 +0,0 @@ -// See https://kit.svelte.dev/docs/types#app -// for information about these interfaces -// and what to do when importing types -declare namespace App { - // interface Locals {} - // interface Platform {} -} diff --git a/packages/kit/test/build-errors/apps/server-only-folder-dynamic-import/src/app.d.ts b/packages/kit/test/build-errors/apps/server-only-folder-dynamic-import/src/app.d.ts deleted file mode 100644 index 917a963999f3..000000000000 --- a/packages/kit/test/build-errors/apps/server-only-folder-dynamic-import/src/app.d.ts +++ /dev/null @@ -1,7 +0,0 @@ -// See https://kit.svelte.dev/docs/types#app -// for information about these interfaces -// and what to do when importing types -declare namespace App { - // interface Locals {} - // interface Platform {} -} diff --git a/packages/kit/test/build-errors/apps/server-only-folder/src/app.d.ts b/packages/kit/test/build-errors/apps/server-only-folder/src/app.d.ts deleted file mode 100644 index 917a963999f3..000000000000 --- a/packages/kit/test/build-errors/apps/server-only-folder/src/app.d.ts +++ /dev/null @@ -1,7 +0,0 @@ -// See https://kit.svelte.dev/docs/types#app -// for information about these interfaces -// and what to do when importing types -declare namespace App { - // interface Locals {} - // interface Platform {} -} diff --git a/packages/kit/test/build-errors/apps/server-only-module-dynamic-import/src/app.d.ts b/packages/kit/test/build-errors/apps/server-only-module-dynamic-import/src/app.d.ts deleted file mode 100644 index 917a963999f3..000000000000 --- a/packages/kit/test/build-errors/apps/server-only-module-dynamic-import/src/app.d.ts +++ /dev/null @@ -1,7 +0,0 @@ -// See https://kit.svelte.dev/docs/types#app -// for information about these interfaces -// and what to do when importing types -declare namespace App { - // interface Locals {} - // interface Platform {} -} diff --git a/packages/kit/test/build-errors/apps/server-only-module/src/app.d.ts b/packages/kit/test/build-errors/apps/server-only-module/src/app.d.ts deleted file mode 100644 index 917a963999f3..000000000000 --- a/packages/kit/test/build-errors/apps/server-only-module/src/app.d.ts +++ /dev/null @@ -1,7 +0,0 @@ -// See https://kit.svelte.dev/docs/types#app -// for information about these interfaces -// and what to do when importing types -declare namespace App { - // interface Locals {} - // interface Platform {} -}