You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For better performance with large objects where you only need a few fields, use `Lite3Buffer.from()` to create a lazy proxy that decodes values on-demand:
// Works with JSON.stringify, spreading, for...of, etc.
69
+
console.log(JSON.stringify(proxy));
70
+
const copy = { ...proxy };
71
+
for (const user ofproxy.users) {
72
+
console.log(user.name);
73
+
}
74
+
```
75
+
76
+
#### Type Safety
77
+
78
+
When creating a proxy from a buffer, the return type defaults to `unknown` for safety (like `JSON.parse`). Provide a type parameter when you trust the data source:
79
+
80
+
```typescript
81
+
interfaceUser {
82
+
name:string;
83
+
age:number;
84
+
}
85
+
86
+
// From buffer - returns unknown by default (safe)
87
+
const data =Lite3Buffer.from(buffer);
88
+
data.name; // TS error: 'unknown' has no property 'name'
89
+
90
+
// With type parameter - returns User (trusted)
91
+
const user =Lite3Buffer.from<User>(buffer);
92
+
user.name; // OK - full autocomplete and type checking
93
+
94
+
// For untrusted sources, consider runtime validation:
0 commit comments