Skip to content

Commit

Permalink
chore: use declare global instead of ambient declarations (#8589)
Browse files Browse the repository at this point in the history
closes #8587
  • Loading branch information
Rich-Harris authored Jan 19, 2023
1 parent 50c2cc8 commit d552ac1
Show file tree
Hide file tree
Showing 17 changed files with 49 additions and 103 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
14 changes: 9 additions & 5 deletions documentation/docs/30-advanced/25-errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
3 changes: 0 additions & 3 deletions packages/adapter-static/test/apps/spa/src/app.d.ts

This file was deleted.

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 {};
1 change: 0 additions & 1 deletion packages/kit/test/apps/options-2/src/app.d.ts

This file was deleted.

7 changes: 0 additions & 7 deletions packages/kit/test/apps/options/source/app.d.ts

This file was deleted.

7 changes: 0 additions & 7 deletions packages/kit/test/apps/writes/src/app.d.ts

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.

This file was deleted.

0 comments on commit d552ac1

Please sign in to comment.