Skip to content

[Bug] types of properties in group are inferred as unknown if results parameter is used #234

Open
@brc-dd

Description

@brc-dd

Environment

  • OS: webcontainers
  • Node Version: 18.20.3
  • Package: @clack/prompts
  • Package Version: v0.10.0

Describe the bug

const options = await p.group(
  {
    injectNpmScripts: async () => {
      return p.confirm({
        message: 'Add VitePress npm scripts to package.json?',
      });
    },

    addNpmScriptsPrefix: async ({ results }) => {
      if (!results.injectNpmScripts) return false;

      return p.confirm({
        message: 'Add a prefix for VitePress npm scripts?',
      });
    },
  },

  {
    onCancel: () => {
      p.cancel('Cancelled.');
      process.exit(0);
    },
  }
);

options here is inferred as:

const options: {
    injectNpmScripts: boolean;
    addNpmScriptsPrefix: unknown;
}

To Reproduce
https://stackblitz.com/edit/node-1z7qkqdt?file=index.ts

Expected behavior
Return correct types:

const options: {
    injectNpmScripts: boolean;
    addNpmScriptsPrefix: boolean;
}

Additional Information
It works fine if we make it ({ results }: any). The generic parameter of group function doesn't work because the functions return cancel symbol too.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status

    Needs triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions