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

Make identifier aliasing optional #580

Open
alecmev opened this issue Jun 29, 2024 · 1 comment
Open

Make identifier aliasing optional #580

alecmev opened this issue Jun 29, 2024 · 1 comment

Comments

@alecmev
Copy link
Contributor

alecmev commented Jun 29, 2024

I found a couple of mentions of the intention of making branding optional, like #433 and #444. It doesn't look like it happened yet, but supplying a custom generateIdentifierType is easy enough:

{
  // ...
  generateIdentifierType: (column, details, config) => {
    const name = kanel.escapeIdentifier(
      pascalCase(details.name) + pascalCase(column.name),
    );

    const configWithoutGenerateIdentifierType = { ...config };
    delete configWithoutGenerateIdentifierType.generateIdentifierType;

    const innerType = kanel.resolveType(
      column,
      details,
      configWithoutGenerateIdentifierType,
    );

    return {
      declarationType: 'typeDeclaration',
      name,
      exportAs: 'named',
      typeDefinition: [
        typeof innerType === 'string' ? innerType : innerType.name,
      ],
      typeImports: typeof innerType === 'string' ? [] : innerType.typeImports,
      comment: [`Identifier type for ${details.schemaName}.${details.name}`],
    };
  },
}

However, I would also like to take this a step further and drop identifier aliasing altogether, so that instead of this:

export type UsersId = string;
export default interface UsersTable {
  id: ColumnType<UsersId, UsersId | undefined, UsersId>;
}

It's just this:

export default interface UsersTable {
  id: ColumnType<string, string | undefined, string>;
}

Type-wise this doesn't get in the way, so this is a low-priority request, of course, but it would be nice to get rid of *Id entries in code completion tooltips. This can probably be accomplished with a plugin, but the number of edge cases feels intimidating.

@kristiandupont
Copy link
Owner

Yeah, this is something I probably need to do since it a popular and reasonable request. The problem is, as you are identifying, that there are many edge cases and combinations possible, so it's not quite as trivial as it sounds.

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