We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Description: Add the ability to add null/undefined objects within ArraySchema type
currently, this is restricted by this check in src/types/ArraySchema.ts#182
if (value === undefined || value === null) { console.error("ArraySchema items cannot be null nor undefined; Use `deleteAt(index)` instead."); return; }
Usecase: My backend for a poker game is already made, and an array is made for the player seating:
export class Table { private _tablePlayers = (Player | null)[]; constructor(numSeats = 4) { this._tablePlayers = new Array(numSeats).fill(null); } }
and somebody can join any seat index, meaning the array can look like this:
[ null, null, { username: "player" }, null, ]
but when converting to a schema
export class Table extends Schema { @type([Player]) _tablePlayers = new ArraySchema<Player>(); constructor(numSeats = 4) { new Array(numSeats).fill(null).forEach((seat, index) => (this._tablePlayers[index] = seat)); } }
this will no longer work, and the array will be empty. as seen in the failing test
alongside null/undefined being integral parts of typescript/javascript, so maybe exclusively for js ecosystem
maybe a separate schema type, such as NullableArraySchema
export class NullableArraySchema<V = any> implements Array<V>, SchemaDecoderCallbacks { }
The text was updated successfully, but these errors were encountered:
Thanks for the suggestion - that'd be a nice addition, can't promise but will try to make it into #173
For now, I'd suggest inserting empty Player instances instead of having the null values.
Player
null
Sorry, something went wrong.
No branches or pull requests
Description & Use case
Description:
Add the ability to add null/undefined objects within ArraySchema type
currently, this is restricted by this check in src/types/ArraySchema.ts#182
Usecase:
My backend for a poker game is already made, and an array is made for the player seating:
and somebody can join any seat index, meaning the array can look like this:
but when converting to a schema
this will no longer work, and the array will be empty. as seen in the failing test
alongside null/undefined being integral parts of typescript/javascript, so maybe exclusively for js ecosystem
Optional: Proposed API
maybe a separate schema type, such as NullableArraySchema
The text was updated successfully, but these errors were encountered: