SchemaStore narrowed to never

Currently trying the example in the readme, not sure if this is a vscode bug but it's narrowing the store's type to never:
import { SchemaStore, Schema } from "@sapphire/string-store";

const Id = {
AgeUpdate: 0,
StrengthUpdate: 1,
};

// Create the store
const store = new SchemaStore()
.add(new Schema(Id.AgeUpdate).int32("age"))
.add(new Schema(Id.StrengthUpdate).float32("strength"));

const buffer = store.serialize(Id.AgeUpdate, { age: 1 }).toString();
import { SchemaStore, Schema } from "@sapphire/string-store";

const Id = {
AgeUpdate: 0,
StrengthUpdate: 1,
};

// Create the store
const store = new SchemaStore()
.add(new Schema(Id.AgeUpdate).int32("age"))
.add(new Schema(Id.StrengthUpdate).float32("strength"));

const buffer = store.serialize(Id.AgeUpdate, { age: 1 }).toString();
No description
Solution:
aka ```ts const Id = { AgeUpdate: 0, StrengthUpdate: 1,...
Jump to solution
13 Replies
Amgelo
AmgeloOP3w ago
not sure if it's something on vscode's side since I don't use it quite often anyways, maybe I missconfigured something
Amgelo
AmgeloOP3w ago
this is what it says in the last #add(), where it gets narrowed down
No description
Amgelo
AmgeloOP3w ago
removing only that last one correctly types it as SchemaStore, and #serialize() no longer type errors
Favna
Favna3w ago
@kyra 🩵🩷🤍🩷🩵
Amgelo
AmgeloOP3w ago
guess I'll have to wait for a while because I just talked to kyra right before they were going to bed like a few hours ago lol awesome library though, it's the perfect customId builder
Favna
Favna3w ago
I wish I was still sleeping but I have to be up to start the day to be on time at the conference I'm going to 😭
Amgelo
AmgeloOP3w ago
oh, adding a const assertion fixes it
Solution
Amgelo
Amgelo3w ago
aka
const Id = {
AgeUpdate: 0,
StrengthUpdate: 1,
} as const;
const Id = {
AgeUpdate: 0,
StrengthUpdate: 1,
} as const;
Amgelo
AmgeloOP3w ago
must be because that way the store's keys don't get widened to number but to the numeric constants instead
kyra
kyra2w ago
Oh, right Yeah that makes a lot of sense By the way, you can alternatively use enum if you're using TS 👀
Amgelo
AmgeloOP2w ago
I personally prefer const objects though that's the example from the readme, I was just copying it lol it's missing the const assertion btw if I wanted to ask about design choices when using the library, should I ask in this channel (other thread)? since it's not really about issues about the library itself but how it's implemented on my side
kyra
kyra2w ago
If they’re support questions, a separate thread. If they’re development questions, I’d say in #utilities-development We use AnswerOverflow here, so it’s best to keep threads single-topic Speaking of which, don’t forget this 👀
Amgelo
AmgeloOP2w ago
almost forgot, thanks
Want results from more Discord servers?
Add your server