Skip to content
New issue

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

bug: Generated command comportnent code has error in import statement when using TypeScript #66

Closed
1 task done
Allianaab2m opened this issue Jan 17, 2022 · 6 comments · Fixed by #67
Closed
1 task done

Comments

@Allianaab2m
Copy link
Contributor

Is there an existing issue for this?

  • I have searched the existing issues

Description of the bug

When I generate a command component using the CLI, the type prefix is missing from the import statement, causing an error.
The other components (listener, arguments, precondition), this error did not occur.

Steps To Reproduce

sapphire generate command [commandName]

Expected behavior

It should generate code like this.

import { ApplyOptions } from '@sapphire/decorators';
import { SubCommandPluginCommand, SubCommandPluginCommandOptions } from '@sapphire/plugin-subcommands';
import type { Message } from 'discord.js';

@ApplyOptions<SubCommandPluginCommandOptions>({
	description: 'A basic command'
})
export class UserCommand extends SubCommandPluginCommand {
	public async messageRun(message: Message) {
		return message.channel.send('Hello world!');
	}
}

Screenshots

No response

Additional context

This is the first time for me to make an issue, and I used machine translation,
so I really apologize if there are any confusing parts.

@UndiedGamer
Copy link

whats your templates/command.ts.sapphire file?
and can you show your file structure with command usage

@Allianaab2m
Copy link
Contributor Author

Allianaab2m commented Jan 17, 2022

I'm not sure, because I've just started using Sapphire, but I probably don't use template.
In .sapphirerc.yml, customFileTemplate is set to false.

projectLanguage: "ts"
locations:
  base: src
  arguments: arguments
  commands: commands
  listeners: listeners
  preconditions: preconditions
customFileTemplates:
  enabled: false
  location: ""

Here is the file structure of the project.
foo.ts is a component that I generated myself.
image

@UndiedGamer
Copy link

UndiedGamer commented Jan 17, 2022

it should work fine i see a test.ts was it generated from cli?

@Allianaab2m
Copy link
Contributor Author

The test.ts is the same as foo.ts. There is probably a problem with the code here, so fix it and send a pull request.
https://github.com/sapphiredev/cli/blob/main/templates/components/command.ts.sapphire

@enxg
Copy link
Collaborator

enxg commented Jan 17, 2022

Normally this should not cause an issue because the TypeScript compiler removes the import when compiling if it's only used as a type. Are you sure this is not an ESLint issue?

But to be consistent with the sapphiredev/examples repo I'm going to merge the PR.

@enxg enxg closed this as completed in #67 Jan 17, 2022
@Allianaab2m
Copy link
Contributor Author

I didn't know about the behavior of the TypeScript compiler for type-only imports.
Thank you very much and sorry for the inconvenience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants