@nolikein/types-livewire3 1.1.2 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,6 +2,28 @@
2
2
 
3
3
  Allows you to use the power of TypeScript with Livewire 3.
4
4
 
5
+ ## Migration From 1.x to 2.x
6
+
7
+ Now all your "LivewireMethods" interfaces should be a `Record<string, (...args: any) => any>` instead of `Record<string, any>`.
8
+
9
+ This means your code pass from:
10
+
11
+ ```typescript
12
+ interface LivewireMethods {
13
+ open: ({ state: boolean })
14
+ }
15
+ ```
16
+
17
+ To:
18
+
19
+ ```typescript
20
+ interface LivewireMethods {
21
+ open: (state: boolean) => ({ state: boolean })
22
+ }
23
+ ```
24
+
25
+ In order to keep the type safety of your methods parameters and return types.
26
+
5
27
  ## Installation
6
28
 
7
29
  npm i -D @nolikein/types-livewire3
@@ -27,7 +49,7 @@ Now you are able to use Livewire and Alpine inside your project. Here is an exam
27
49
  ```ts
28
50
  import { Livewire, Alpine } from '@/your_livewire_path';
29
51
 
30
- Alpine.data('YourCOmponent', () => {});
52
+ Alpine.data('YourComponent', () => {});
31
53
  Livewire.start();
32
54
  ```
33
55
 
@@ -62,7 +84,7 @@ interface LivewireData {
62
84
  // Your Livewire public methods
63
85
  interface LivewireMethods {
64
86
  // The livewire component has an "open" method that you can call then return a boolean
65
- open(): boolean
87
+ open(state: boolean): ({ state: boolean })
66
88
  }
67
89
 
68
90
  /**
@@ -80,7 +102,7 @@ export default (
80
102
  },
81
103
 
82
104
  callBackendToOpen(): void {
83
- this.$wire.$call('open', (data: ({ state: boolean })) => {
105
+ this.$wire.$call('open', true).then(data) => {
84
106
  console.log("The livewire component has updated its open property with the value " + data.state);
85
107
  });
86
108
  },
@@ -415,7 +415,7 @@ export interface LivewireMagics<LivewireData, LivewireMethods> {
415
415
  * @param name
416
416
  * @param live false by default
417
417
  */
418
- $entangle(name: string, live?: boolean): EntangleInstance;
418
+ $entangle(name: string & keyof LivewireData, live?: boolean): EntangleInstance;
419
419
  /**
420
420
  * Watch the value of a property for changes...
421
421
  * Usage: Alpine.$watch('count', (value, old) => { ... })
@@ -423,7 +423,7 @@ export interface LivewireMagics<LivewireData, LivewireMethods> {
423
423
  * @param name
424
424
  * @param callback
425
425
  */
426
- $watch(name: string, callback: (value: unknown, old: unknown) => void): Promise<unknown>;
426
+ $watch(name: string & keyof LivewireData, callback: (value: unknown, old: unknown) => void): Promise<unknown>;
427
427
  /**
428
428
  * Refresh a component by sending a commit to the server
429
429
  * to re-render the HTML and swap it into the page...
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nolikein/types-livewire3",
3
- "version": "1.1.2",
3
+ "version": "2.0.1",
4
4
  "description": "Typescript content for Laravel Livewire 3",
5
5
  "license": "MIT",
6
6
  "author": "Côme Wasik",
@@ -27,4 +27,4 @@
27
27
  "@types/alpinejs": "^3.13.11",
28
28
  "typescript": "^5.9.2"
29
29
  }
30
- }
30
+ }