Comments (4)
Hi @oravecz, we documented this issue here, in case you're interested in the details.
Ultimately, the key issue that causes this type error is on line 12:
export interface AttributeValue {
v?: object; // 👈 An `object` isn't guaranteed to be JSON-serializable
}
In addition, from looking at your example, your best shot will be to use type
instead of interfaces
, if you are in control of those type definitions, and your application allows it.
- Change this
object
toJsonObject
- Change
interface
totype
(which aren't "open" by default, and thus helps TypeScript understand that there won't be any non-JSON fields added to the type elsewhere)
Here is an adjusted example that works around this problem.
Hope this helps to explain and solves your issue. Feel free to re-open this issue if you have any further questions! 🙏
from liveblocks.
Yes, that is the documentation I had referenced in the ticket.
The docs might be helped by coming out and stating "An object
isn't guaranteed to be JSON-serializable"
Unfortunately for me, this interface is external to my codebase, and seems like it will prevent me from using LiveBlocks.
I'm curious also, why an "override" can't be provided for the developer to vouch that the Storage instance is serializable. I understand the desire to be pedantic. You probably fielded situations where non-serializable payloads were passed in the past, and are trying to avoid the issue.
But in doing so, you have created a hurdle for developers who need to use the TS any
type. For us, this comes about because we are using OpenAPI to generate the payloads and skeletons for a Java backend, so some codegen restriction on a different language is impeding our ability to generate a more precise TS interface.
Can you say more about regarding the idea to provide developers with an option to remove the serialization check you are trying to enforce via types?
from liveblocks.
Yeah, this is tricky. One reason the types are like this is because we also use them to automatically derive the immutable JSON types from these definitions. Not enforing JSON-serializableness here will lead to many unexpected "unknowns" down the road, which can be even more confusing.
To unblock you, if you don't control the generated interface types, another workaround for you can be the following:
const attributes: (Attribute & Lson)[] = [];
new LiveList<Attribute & Lson>(attributes)
// ^^^^^^^^^^^^^^^^ Manually tell TypeScript your Attribute type will be JSON-serializable
Hope that helps!
from liveblocks.
Can we extend that Playground example a little bit more?
const attributes: (Attribute & Lson)[] = [];
const attribute = attributes[0] as unknown as (Attribute & LsonObject);
const list = new LiveList<Attribute & Lson>(attributes)
const item = new LiveObject<Attribute & LsonObject>(attribute);
list.push(item);
The last line doesn't seem to work with the types specified.
from liveblocks.
Related Issues (20)
- Updating from v1.10.0 to v1.10.1 throws "process is not defined" error HOT 5
- process is undefined error on Vite project HOT 6
- Circular Reference in JSON HOT 2
- Using an async call in an event handler HOT 1
- RangeError: Maximum call stack size exceeded HOT 1
- Please explain how to update Yjs document from the backend with streaming AND keeping the formatting.
- Clients can crash in various ways if comment is deleted that an inbox notification still references
- Nested Rooms in React causing error HOT 8
- Add query regex filtering to metadata custom data
- liveblocksEnhancer does not mix in LiveblocksContext to the state HOT 1
- API endpoint for filtering threads by roomId prefix
- Bug: Comment Splits into Two When Typing in Vietnamese and Pressing Enter HOT 1
- OpenAPI spec is invalid
- Export the YDocUpdatedEvent type HOT 3
- Document 10-permission limit and any other limits for access tokens
- Tiptap example error breaks Liveblocks connection
- Disable Comment Notifications from all rooms HOT 3
- Remove tiptap duplicate problem
- Set Function Not Working As Inteneded HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from liveblocks.