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
16 Replies
Amgelo
AmgeloOP2mo 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
AmgeloOP2mo ago
this is what it says in the last #add(), where it gets narrowed down
No description
Amgelo
AmgeloOP2mo ago
removing only that last one correctly types it as SchemaStore, and #serialize() no longer type errors
Favna
Favna2mo ago
@kyra 🩵🩷🤍🩷🩵
Amgelo
AmgeloOP2mo 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
Favna2mo 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
AmgeloOP2mo ago
oh, adding a const assertion fixes it
Solution
Amgelo
Amgelo2mo ago
aka
const Id = {
AgeUpdate: 0,
StrengthUpdate: 1,
} as const;
const Id = {
AgeUpdate: 0,
StrengthUpdate: 1,
} as const;
Amgelo
AmgeloOP2mo ago
must be because that way the store's keys don't get widened to number but to the numeric constants instead
kyra
kyra2mo ago
Oh, right Yeah that makes a lot of sense By the way, you can alternatively use enum if you're using TS 👀
Amgelo
AmgeloOP2mo 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
kyra2mo 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
AmgeloOP2mo ago
almost forgot, thanks
Amgelo
AmgeloOP4w ago
thanks! unrelated question but could I by chance get a reply in #Serializing string-store result inside another schema :crySparkle:
kyra
kyra4w ago
Yeah I'm on it
Want results from more Discord servers?
Add your server