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

Type error on arguments #148

Closed
Teages opened this issue Jun 4, 2024 · 1 comment
Closed

Type error on arguments #148

Teages opened this issue Jun 4, 2024 · 1 comment

Comments

@Teages
Copy link

Teages commented Jun 4, 2024

Environment

  • version: last release and main branch
  • Node JS: v20.12.0 but it doesn't matter

Reproduction

just use ~/playground/hello.ts

Here is a copy:

import consola from "consola";
import { defineCommand, createMain } from "../src";

const command = defineCommand({
  meta: {
    name: "hello",
    version: "1.0.0",
    description: "My Awesome CLI App",
  },
  args: {
    name: {
      type: "positional",
      description: "Your name",
      required: true,
    },
    friendly: {
      type: "boolean",
      description: "Use friendly greeting",
    },
    age: {
      type: "number",
      description: "Your age",
      required: false,
    },
    adj: {
      type: "enum",
      description: "Adjective to use in greeting",
      options: ["awesome", "cool", "nice"],
      default: "awesome",
      required: false,
    },
  },
  run({ args }) {
    consola.log(args);
    const msg = [
      args.friendly ? "Hi" : "Greetings",
      args.adj || "",
      args.name,
      args.age ? `You are ${args.age} years old.` : "",
    ]
      .filter(Boolean)
      .join(" ");

    consola.log(msg);
  },
});

createMain(command)({});

Describe the bug

There are two errors on type:

  1. args.adj should be string or string | number but now it is string[], in further it had better to be 'awesome' | 'cool' | 'nice'
  2. friendly could be undefined if not provided, but here typescript think it is non-nullable

(although age is not required, it will throw an error Invalid value for argument: --age (undefined). Expected a number. if not provided age. It is not related to this issue)

Additional context

I will have a pr to fix the problem.

Logs

No response

@Teages Teages mentioned this issue Jun 4, 2024
8 tasks
@Teages
Copy link
Author

Teages commented Jun 4, 2024

will resolve by #132

@Teages Teages closed this as completed Jun 4, 2024
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.

1 participant