interactionHandler parse showing TS '...cannot be named without reference to...' error

When attempting to make a very basic interaction handler I'm getting the pictured compiler error. The guide suggests that I shouldn't need to explicitly type the parse function so I'm not sure why I'm getting this error. The code:
import { ApplyOptions } from '@sapphire/decorators';
import { InteractionHandler, InteractionHandlerOptions, InteractionHandlerTypes } from '@sapphire/framework';
import type { ButtonInteraction } from 'discord.js';

@ApplyOptions<InteractionHandlerOptions>({
interactionHandlerType: InteractionHandlerTypes.Button
})
export class PollHandler extends InteractionHandler {

public parse(interaction: ButtonInteraction) {
if (interaction.id.startsWith('poll')) {
return this.none();
}
return this.some('Hello button');
}

public async run(interaction: ButtonInteraction, promisedPoll: InteractionHandler.ParseResult<this>) {
interaction.reply({ content: promisedPoll, ephemeral: true });
}

}
import { ApplyOptions } from '@sapphire/decorators';
import { InteractionHandler, InteractionHandlerOptions, InteractionHandlerTypes } from '@sapphire/framework';
import type { ButtonInteraction } from 'discord.js';

@ApplyOptions<InteractionHandlerOptions>({
interactionHandlerType: InteractionHandlerTypes.Button
})
export class PollHandler extends InteractionHandler {

public parse(interaction: ButtonInteraction) {
if (interaction.id.startsWith('poll')) {
return this.none();
}
return this.some('Hello button');
}

public async run(interaction: ButtonInteraction, promisedPoll: InteractionHandler.ParseResult<this>) {
interaction.reply({ content: promisedPoll, ephemeral: true });
}

}
10 Replies
Ben
Ben2y ago
Heres the error in text if needed
10 public parse(interaction: ButtonInteraction) {
~~~~~

src/interaction-handlers/poll.ts:10:9 - error TS2742: The inferred type of 'parse' cannot be named without a reference to '.pnpm/@[email protected]/node_modules/@sapphire/result/dist/lib/Option/Some'. This is likely not portable. A type annotation is necessary.

10 public parse(interaction: ButtonInteraction) {
~~~~~
10 public parse(interaction: ButtonInteraction) {
~~~~~

src/interaction-handlers/poll.ts:10:9 - error TS2742: The inferred type of 'parse' cannot be named without a reference to '.pnpm/@[email protected]/node_modules/@sapphire/result/dist/lib/Option/Some'. This is likely not portable. A type annotation is necessary.

10 public parse(interaction: ButtonInteraction) {
~~~~~
Sawako
Sawako2y ago
Downgrade sapphire result To 2.6.0
Favna
Favna2y ago
What why would a downgrade of result be needed lol In fact you shouldn't need to manually install result at all In fact 2.6.0 is latest @kaname-png smhhh It looks like a pnpm issue Ben maybe you can do me a solid here @Ben855. Add a tag to @Spinel pnpm with content:
When using pnpm with Sapphire Framework make sure to configure pnpm to hoist all Sapphire packages. This is required because of how Sapphire leverages JavaScript and TypeScript and it doesn't work if the Sapphire packages do not physically exist in `node_modules/.pnpm/@sapphire/`

In your `.npmrc` add a line:
`public-hoist-pattern[]=*@sapphire*`

Or with a single command line:

\`\`\`sh
echo "public-hoist-pattern[]=*@sapphire*" >> .npmrc
\`\`\`
When using pnpm with Sapphire Framework make sure to configure pnpm to hoist all Sapphire packages. This is required because of how Sapphire leverages JavaScript and TypeScript and it doesn't work if the Sapphire packages do not physically exist in `node_modules/.pnpm/@sapphire/`

In your `.npmrc` add a line:
`public-hoist-pattern[]=*@sapphire*`

Or with a single command line:

\`\`\`sh
echo "public-hoist-pattern[]=*@sapphire*" >> .npmrc
\`\`\`
and if you can add a page with about that content in the Additional Information category of the guide that'd be even more awesome
Ben
Ben2y ago
I’ll give that fix a shot and the open a few PRs in several hours
Sawako
Sawako2y ago
Pinning the version to 2.6.0 fixed the problem for me using pnpm ¯\_(ツ)_/¯
Ben
Ben2y ago
Unless I missed something here, adding the hoist pattern doesnt seem to have causes pnpm to do anything differently. Everything in the @sapphire dir in node_modules is still simlinked .
Ben
Ben2y ago
I did also yeet my node modules and lockfile then reinstalled
Favna
Favna2y ago
adding framework without hoist:
Favna
Favna2y ago
adding framework with hoist:
Favna
Favna2y ago
so yes it does change things TypeScript doesn't read types that aren't in node_modules/@types/ or node_modules/**/package.json:types/typings/export.types
Want results from more Discord servers?
Add your server