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

Way of extending ActionType to have type definition for action added with setActionType #422

Open
JacopoPatroclo opened this issue Mar 26, 2024 · 1 comment

Comments

@JacopoPatroclo
Copy link

JacopoPatroclo commented Mar 26, 2024

Issue

Currently, when creating a new action type using the setActionType function, there's no direct provision to extend the ActionType type to include the new type and options type. It would be beneficial to add the ability to extend the ActionType type, simplifying the process for developers to share custom action types.

Proposal

It could be nice to have something like this:

declare module 'node-plop' {
   interface ActionType extends BaseActionType {
      type: 'your-type',
      someOption: string
   }
}

But of course, we need to make ActionType an interface and I'm not sure it's possible at this time. I would love to contribute to this enhancement. Let me know if it's something that makes sense to create.

If something is not clear I can extend my explanation with more examples.

@awhitford
Copy link

awhitford commented Oct 17, 2024

I am using TypeScript and creating custom actions, and I too ran into this issue. I'd love to see an improvement here so that the TypeScript was cleaner.

Check out this test:

// use the custom action
plop.setGenerator("test", {
prompts: [],
actions: [
{
type: "doTheThing",
configProp: "available from the config param",
} as CustomActionConfig<"doTheThing">,
{
type: "doTheAsyncThing",
speed: "slow",
} as CustomActionConfig<"doTheAsyncThing">,
],
});
}

You can see that there is a CustomActionConfig<"customType"> type. Alas, I don't see a way of importing it. And I don't see their code actually restricting the properties.

Also see #439.

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

No branches or pull requests

2 participants