Decorator issue

Having a weird issue with the decorators.. I've just updated all of my dependencies to the absolute latest version, but the error is still persisting here. It seems to be quite random, but there are steps I can take every time to get the error. Note that I've always had "experimentalDecorators": true, as part of my tsconfig - everything I've seen so far suggests adding that. When I remove "experimentalDecorators": true,, the same error appears across every file, not just the one file with the issue. Notably, when I see the issue, I also have a bunch of other errors (pointing to the discord.js package inside nodemodules, something about ECMAScript 2015, and a whole bunch of errors across other files that aren't normally there. Also, the project compiles fine, the decorator throwing the issue is working as expecred, but the whole project is going mental with errors that it's never reported before. To reproduce this, I; - Copy an existing file - Rename the file/class name Then, I see the error reported on the decorator, Then, several other errors appear
Unable to resolve signature of class decorator when called as an expression.
The runtime will invoke the decorator with 2 arguments, but the decorator expects 1.ts(1238)
Unable to resolve signature of class decorator when called as an expression.
The runtime will invoke the decorator with 2 arguments, but the decorator expects 1.ts(1238)
5 Replies
Bejasc
BejascOP6mo ago
No description
Bejasc
BejascOP6mo ago
{
"compilerOptions": {
"module": "commonjs",
"target": "es2022",
"rootDir": "src",
"tsBuildInfoFile": "dist/.tsbuildinfo",
"outDir": "dist",
"lib": ["ESNext", "ESNext.Array", "ESNext.AsyncIterable", "ESNext.Intl", "ES2015.Symbol", "DOM"],
"sourceMap": true,
"inlineSources": true,
"incremental": true,
"esModuleInterop": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"resolveJsonModule": true,
"skipLibCheck": true
},
"include": ["src/**/*", "/src/data/**/*.json"],
"exclude": ["node_modules", "GPT Helper"]
}
{
"compilerOptions": {
"module": "commonjs",
"target": "es2022",
"rootDir": "src",
"tsBuildInfoFile": "dist/.tsbuildinfo",
"outDir": "dist",
"lib": ["ESNext", "ESNext.Array", "ESNext.AsyncIterable", "ESNext.Intl", "ES2015.Symbol", "DOM"],
"sourceMap": true,
"inlineSources": true,
"incremental": true,
"esModuleInterop": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"resolveJsonModule": true,
"skipLibCheck": true
},
"include": ["src/**/*", "/src/data/**/*.json"],
"exclude": ["node_modules", "GPT Helper"]
}
@ApplyOptions<IDrpgCommandOptions>({
name: "GM Add Control Points",
aliases: ["!control", "!lcp", "!cont"],
shortDesc: "Add Control Points to a Location.",
description: `Add or remove Control Points to a Location for the provided faction .
Use either an Named Size or a number.`,
fullCategory: ["Game Master"],
showInHelpMenu: true,
examples: [
{
title: "Add a 'Medium' amount of Control Points",
description: "Add the pre-configured 'Medium' amount of Control Points, for the Galactic Empire on Bespin.",
command: "!control imperial bespin medium",
},
],
preconditions: ["GmOnly"],
})
export class GMAddControlPointsCommand extends DrpgCommand {
public async messageRun(message: Message, args: Args): Promise<Message> {
@ApplyOptions<IDrpgCommandOptions>({
name: "GM Add Control Points",
aliases: ["!control", "!lcp", "!cont"],
shortDesc: "Add Control Points to a Location.",
description: `Add or remove Control Points to a Location for the provided faction .
Use either an Named Size or a number.`,
fullCategory: ["Game Master"],
showInHelpMenu: true,
examples: [
{
title: "Add a 'Medium' amount of Control Points",
description: "Add the pre-configured 'Medium' amount of Control Points, for the Galactic Empire on Bespin.",
command: "!control imperial bespin medium",
},
],
preconditions: ["GmOnly"],
})
export class GMAddControlPointsCommand extends DrpgCommand {
public async messageRun(message: Message, args: Args): Promise<Message> {
Works without issue, reports the error
Unable to resolve signature of class decorator when called as an expression.
The runtime will invoke the decorator with 2 arguments, but the decorator expects 1.ts(1238)
Unable to resolve signature of class decorator when called as an expression.
The runtime will invoke the decorator with 2 arguments, but the decorator expects 1.ts(1238)
@ApplyOptions<IDrpgCommandOptions>({
name: "NPC Info",
aliases: ["!npcinfo", "!npcstats", "!npci"],
fullCategory: ["Game Master"],
shortDesc: "View NPC Stats",
description: `View the stats of an existing NPC`,
showInHelpMenu: true,
})
export class HookCommand extends DrpgCommand {
public override async registerApplicationCommands(registry: ApplicationCommandRegistry) {
@ApplyOptions<IDrpgCommandOptions>({
name: "NPC Info",
aliases: ["!npcinfo", "!npcstats", "!npci"],
fullCategory: ["Game Master"],
shortDesc: "View NPC Stats",
description: `View the stats of an existing NPC`,
showInHelpMenu: true,
})
export class HookCommand extends DrpgCommand {
public override async registerApplicationCommands(registry: ApplicationCommandRegistry) {
Works without issue, no error reported These errors are only reported when I have the file open that has the decorator error Also to add, I've also tried clearing out the dist, node modules, and package lock
Spinel
Spinel6mo ago
In TypeScript v5 the TypeScript developers shipped initial support for the upcoming Decorators proposal for JavaScript. This means that by default TypeScript will allow the usages of decorators in your TypeScript code, unlike before where it would throw an error when doing so without proper configuration. This is a pitfal however, as many libraries, including @sapphire/decorators, are not yet updated to use the new decorators proposal. This means that you will have to enable the experimental decorators in your tsconfig.json file. To do so, add the following to your tsconfig.json file:
{
"compilerOptions": {
"experimentalDecorators": true
}
}
{
"compilerOptions": {
"experimentalDecorators": true
}
}
Bejasc
BejascOP6mo ago
@Boomeravna As mentioned, I already have this enabled This is my tsconfig, I've been using experimentalDecorators for quite a while, at least 18mo, probably longer (not at pc to check exact)
Favna
Favna6mo ago
try setting your moduleResolution to node16 the default when module is set to commonjs is
'node10' (previously called 'node') for Node.js versions older than v10, which only support CommonJS require. You probably won’t need to use node10 in modern code.
see https://www.typescriptlang.org/tsconfig/#moduleResolution
Want results from more Discord servers?
Add your server