Async Preconditions

Helloo! It seems that I am unable to create a precondition that is async, whenever I try to write one with async. I get The inferred type of 'chatInputRun' cannot be named without a reference to '.pnpm/@[email protected]/node_modules/@sapphire/result'. This is likely not portable. A type annotation is necessary. Here is the code in question:
public override async chatInputRun(interaction: Interaction) {
const guildPlayer = this.container.queue.get(interaction.guildId!);
if (!guildPlayer) return this.ok();
const {
music: { djs }
} = await this.container.settings.getUserSetting(guildPlayer.owner);

if (guildPlayer.owner !== interaction.user.id && !djs?.includes(interaction.user.id)) {
return this.error({
message: 'The owner of this music session does not have you as a DJ. Have them add you using `/dj add`!',
identifier: 'PermissionsMissing'
});
}
return this.ok();
}
public override async chatInputRun(interaction: Interaction) {
const guildPlayer = this.container.queue.get(interaction.guildId!);
if (!guildPlayer) return this.ok();
const {
music: { djs }
} = await this.container.settings.getUserSetting(guildPlayer.owner);

if (guildPlayer.owner !== interaction.user.id && !djs?.includes(interaction.user.id)) {
return this.error({
message: 'The owner of this music session does not have you as a DJ. Have them add you using `/dj add`!',
identifier: 'PermissionsMissing'
});
}
return this.ok();
}
12 Replies
Favna
Favna16mo ago
cannot reproduce. Update all your dependencies, Nuke your node_modules and lockfile and reinstall dependencies
No description
Dolliwyx
DolliwyxOP16mo ago
I still receive the same error, I've done the following: - pnpm update --latest - Delete node_modules and pnpm_lock.yaml - pnpm install - Restarted TS language server
Favna
Favna16mo ago
Did you add the hoist pattern that you have to use when using pnpm? pnpm is well known to have issues with TypeScript when dealing with packages that use module augmentations and transitive dependencies because they do not patch typescript internally to actually redirect the server to scan whever the hell they place the dependencies that is not node_modules. It's really not an all that good package manager because of its major issues with typescript. Compare that to Yarn which also has a pnp mode, when enabled it also patches TypeScript to actually ensure that it can read the files when it should.
Lioness100
Lioness10016mo ago
You could also follow the ts instructions and manually annotate the return type (Ok, I think?)
Favna
Favna16mo ago
true it's just a bit of a PITA to have to do that but yeah it's : Precondition.AsyncResult btw
Dolliwyx
DolliwyxOP16mo ago
I've tried annotating it to Promise<PreconditionResult> but it gave me more errors than before kekw it's like this I see
Favna
Favna16mo ago
that is an alias for type AsyncPreconditionResult = Promise<Result<unknown, UserError>> so yeah not the same as Promise<PreconditionResult> Promise<PreconditionResult> is Promise<Awaitable<Result<unknown, UserError>>>
Dolliwyx
DolliwyxOP16mo ago
ah I see I see pepeThink the few ways I can get past this is by either manually annotating the return type, or by making the switch to yarn or npm?
Lioness100
Lioness10016mo ago
One of those sounds easier than the other kekw
Favna
Favna16mo ago
(im sure you mean switching to yarn right lioness)
Lioness100
Lioness10016mo ago
(oh for sure)
ararou!
ararou!16mo ago
pls do
Want results from more Discord servers?
Add your server