Decorator function return type is not assignable to type #815
Answered
by
simplenotezy
simplenotezy
asked this question in
Q&A
-
We are upgrading Nest.js from 8-9 and we're having issues with nest-commander. We are getting the following error:
When using the basic example: import { Command, CommandRunner, Option } from 'nest-commander';
import { LogService } from './log.service';
interface BasicCommandOptions {
string?: string;
boolean?: boolean;
number?: number;
}
@Command({ name: 'basic', description: 'A parameter parse' })
export class BasicCommand implements CommandRunner {
constructor(private readonly logService: LogService) {}
async run(passedParam: string[], options?: BasicCommandOptions): Promise<void> {
if (options?.boolean !== undefined && options?.boolean !== null) {
this.runWithBoolean(passedParam, options.boolean);
} else if (options?.number) {
this.runWithNumber(passedParam, options.number);
} else if (options?.string) {
this.runWithString(passedParam, options.string);
} else {
this.runWithNone(passedParam);
}
}
@Option({
flags: '-n, --number [number]',
description: 'A basic number parser',
})
parseNumber(val: string): number {
return Number(val);
}
@Option({
flags: '-s, --string [string]',
description: 'A string return',
})
parseString(val: string): string {
return val;
}
@Option({
flags: '-b, --boolean [boolean]',
description: 'A boolean parser',
})
parseBoolean(val: string): boolean {
return JSON.parse(val);
}
runWithString(param: string[], option: string): void {
this.logService.log({ param, string: option });
}
runWithNumber(param: string[], option: number): void {
this.logService.log({ param, number: option });
}
runWithBoolean(param: string[], option: boolean): void {
this.logService.log({ param, boolean: option });
}
runWithNone(param: string[]): void {
this.logService.log({ param });
}
} Not sure why. This is our tsconfig: {
"compilerOptions": {
"module": "commonjs",
"removeComments": true,
"esModuleInterop": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"target": "es2017",
"sourceMap": true,
"inlineSources": true,
"declaration": true,
"outDir": "./dist",
"baseUrl": "./",
"incremental": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"strictBindCallApply": false,
"forceConsistentCasingInFileNames": false,
"noFallthroughCasesInSwitch": false,
"noEmitHelpers": true,
"importHelpers": true
},
"exclude": ["**/node_modules/**", "**/dist/**"]
} And our dependencies: {
"dependencies": {
"@nestjs/apollo": "^10.2.0",
"@nestjs/common": "^9.3.9",
"@nestjs/config": "^2.3.1",
"@nestjs/core": "^9.3.9",
"@nestjs/cqrs": "^9.0.3",
"@nestjs/platform-express": "^9.3.9",
"@nestjs/schedule": "^2.2.0",
"nest-commander": "^3.6.1",
"reflect-metadata": "^0.1.13",
"tslib": "^2.4.0",
"tslint": "^6.1.3"
},
"devDependencies": {
"@nestjs/cli": "^9.2.0",
"@nestjs/schematics": "^9.0.4",
"@nestjs/testing": "^9.3.9",
"@types/node": "^16",
"@typescript-eslint/eslint-plugin": "^5.54.1",
"@typescript-eslint/parser": "^5.54.1",
"eslint": "^8.35.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-prettier": "^8.7.0",
"eslint-import-resolver-typescript": "^3.5.3",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-prettier": "^4.2.1",
"nyc": "^15.1.0",
"prettier": "^2.3.2",
"ts-jest": "^27.1.3",
"ts-loader": "^9.2.8",
"ts-node": "^10.7.0",
"tsconfig-paths": "^3.9.0",
"typescript": "^4.3.5"
}
} |
Beta Was this translation helpful? Give feedback.
Answered by
simplenotezy
Mar 8, 2023
Replies: 1 comment
-
Whoops. Did another search, without including the |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
jmcdo29
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Whoops. Did another search, without including the
BasicCommand
and this showed up: #578