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

Plop does not handle | null when adding lines #380

Open
mljlynch opened this issue May 31, 2023 · 1 comment
Open

Plop does not handle | null when adding lines #380

mljlynch opened this issue May 31, 2023 · 1 comment

Comments

@mljlynch
Copy link

When appending a link to a typescript type with | null included, plop borks the remaining conditional types in the type definition.

Action:

     {
       type: 'append',
       path: 'src/context/AsyncStorage/AsyncStorage.context.types.tsx',
       pattern: `/* PLOP_INJECT_ASYNC_STORAGE_VALUE_TYPE */`,
       template: `{{camelCase name}}: {{type}} | null;`,
     },

expected behavior:

export type AsyncStorageContextValues = {
  /* PLOP_INJECT_ASYNC_STORAGE_VALUE_TYPE */
  value1 = Type | null;
  value2 = Type | null;
  ...
}

Observed behavior:

export type AsyncStorageContextValues = {
  /* PLOP_INJECT_ASYNC_STORAGE_VALUE_TYPE */
  value1 = Type | null;
  value2 = Type |
  value3 = Type |
  ...
}
@mljlynch
Copy link
Author

mljlynch commented Jun 1, 2023

It looks like this is due to:

https://github.com/plopjs/plop/blob/main/packages/node-plop/src/actions/append.js

This line does not handle the "|" (or) operator in Regex even though we need to be able to plop types into typescript.

    const lastPartWithoutDuplicates = lastPart.replace(
      new RegExp(separator + stringToAppend, "g"),
      ""
    );

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

1 participant