Skip to content

Commit

Permalink
use declare global instead of ambient declarations - closes #8587
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Jan 18, 2023
1 parent 1972a8f commit 75a367e
Show file tree
Hide file tree
Showing 16 changed files with 66 additions and 96 deletions.
16 changes: 10 additions & 6 deletions documentation/docs/25-build-and-deploy/60-adapter-cloudflare.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 8 additions & 4 deletions documentation/docs/30-advanced/20-hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 8 additions & 4 deletions documentation/docs/30-advanced/25-errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,16 @@ If you're using TypeScript and need to customize the shape of errors, you can do
```ts
/// 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.
6 changes: 4 additions & 2 deletions packages/adapter-static/test/apps/spa/src/app.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/// <reference types="@sveltejs/kit" />
declare global {
namespace App {}
}

declare namespace App {}
export {};
20 changes: 12 additions & 8 deletions packages/kit/test/apps/basics/src/app.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
declare namespace App {
interface Locals {
answer: number;
name?: string;
key: string;
params: Record<string, string>;
}
declare global {
namespace App {
interface Locals {
answer: number;
name?: string;
key: string;
params: Record<string, string>;
}

interface Platform {}
interface Platform {}
}
}

export {};
12 changes: 7 additions & 5 deletions packages/kit/test/apps/options/source/app.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/// <reference types="@sveltejs/kit" />
declare global {
namespace App {
interface Locals {}

declare namespace App {
interface Locals {}

interface Platform {}
interface Platform {}
}
}

export {};
12 changes: 7 additions & 5 deletions packages/kit/test/apps/writes/src/app.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/// <reference types="@sveltejs/kit" />
declare global {
namespace App {
interface Locals {}

declare namespace App {
interface Locals {}

interface Platform {}
interface Platform {}
}
}

export {};

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit 75a367e

Please sign in to comment.