From 4084524a4a69e0b83b78077a0e3edae26ae4612a Mon Sep 17 00:00:00 2001 From: Rodrigo Mesquita <30835404+rrmesquita@users.noreply.github.com> Date: Thu, 30 Nov 2023 06:28:53 -0300 Subject: [PATCH 1/4] feat: generate types that match generated js --- src/Output/Types.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Output/Types.php b/src/Output/Types.php index 45ba303c..69a720f9 100644 --- a/src/Output/Types.php +++ b/src/Output/Types.php @@ -26,11 +26,15 @@ public function __toString(): string }); return <<toJson(JSON_PRETTY_PRINT)} } -export {}; +declare global { + var route: typeof routeFn +} +export declare const Ziggy: Config; JAVASCRIPT; } From 9fa1a983e6a722eb581662a2ea95f0a084c7ef95 Mon Sep 17 00:00:00 2001 From: Rodrigo Mesquita <30835404+rrmesquita@users.noreply.github.com> Date: Thu, 30 Nov 2023 06:59:19 -0300 Subject: [PATCH 2/4] chore: remove typescript tip from README --- README.md | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/README.md b/README.md index 6186a4ed..23b709a0 100644 --- a/README.md +++ b/README.md @@ -267,16 +267,6 @@ To generate route types, run the `ziggy:generate` command with the `--types` or php artisan ziggy:generate --types ``` -To make your IDE aware that Ziggy's `route()` helper is available globally, and to type it correctly, add a declaration like this in a `.d.ts` file somewhere in your project: - -```ts -import routeFn from 'ziggy-js'; - -declare global { - var route: typeof routeFn; -} -``` - If you don't have Ziggy's NPM package installed, add the following to your `jsconfig.json` or `tsconfig.json` to load Ziggy's types from your vendor directory: ```json From 2227b73b3633144718aba4889fc57b901fa50ba2 Mon Sep 17 00:00:00 2001 From: Rodrigo Mesquita <30835404+rrmesquita@users.noreply.github.com> Date: Thu, 30 Nov 2023 07:01:33 -0300 Subject: [PATCH 3/4] chore: move generated comment to the top --- src/Output/Types.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Output/Types.php b/src/Output/Types.php index 69a720f9..e36d7d53 100644 --- a/src/Output/Types.php +++ b/src/Output/Types.php @@ -26,8 +26,8 @@ public function __toString(): string }); return <<toJson(JSON_PRETTY_PRINT)} } From 9a505eb07e1dcff24cd3cc10b1c73a979c91036b Mon Sep 17 00:00:00 2001 From: Rodrigo Mesquita <30835404+rrmesquita@users.noreply.github.com> Date: Thu, 30 Nov 2023 07:04:57 -0300 Subject: [PATCH 4/4] fix: update typings in test fixtures --- tests/fixtures/ziggy-7.d.ts | 6 +++++- tests/fixtures/ziggy.d.ts | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/tests/fixtures/ziggy-7.d.ts b/tests/fixtures/ziggy-7.d.ts index c71ee83b..8c95a642 100644 --- a/tests/fixtures/ziggy-7.d.ts +++ b/tests/fixtures/ziggy-7.d.ts @@ -1,4 +1,5 @@ /* This file is generated by Ziggy. */ +import routeFn, { type Config } from 'ziggy-js' declare module 'ziggy-js' { interface RouteList { "posts.index": [], @@ -18,4 +19,7 @@ declare module 'ziggy-js' { ] } } -export {}; +declare global { + var route: typeof routeFn +} +export declare const Ziggy: Config; diff --git a/tests/fixtures/ziggy.d.ts b/tests/fixtures/ziggy.d.ts index 90ea8c89..58a6d52e 100644 --- a/tests/fixtures/ziggy.d.ts +++ b/tests/fixtures/ziggy.d.ts @@ -1,4 +1,5 @@ /* This file is generated by Ziggy. */ +import routeFn, { type Config } from 'ziggy-js' declare module 'ziggy-js' { interface RouteList { "posts.index": [], @@ -9,4 +10,7 @@ declare module 'ziggy-js' { ] } } -export {}; +declare global { + var route: typeof routeFn +} +export declare const Ziggy: Config;