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

Generated key typings creates unsupported keys #582

Open
5 tasks done
V-ed opened this issue Oct 5, 2023 · 0 comments
Open
5 tasks done

Generated key typings creates unsupported keys #582

V-ed opened this issue Oct 5, 2023 · 0 comments

Comments

@V-ed
Copy link

V-ed commented Oct 5, 2023

Describe the bug

When using the typesOutputPath option, the package generates a file containing a Record of (abstracted for this issue) type KeyMap = Record<string, string | KeyMap> which in itself is working fine.

The issue stems from how the key paths are generated, which creates keys with "sub"-keys that are unusable ('admin' | 'admin.labels'| [...]). See picture below for a clearer picture on what I'm trying to say :

image
In the example above, only 'admin.emails.register.body.cta-button' and 'admin.emails.register.body.greetings' should be shown (this example is trimmed down), as all the keys above them are unusable keys that are generated via the export type Path and its sister types PathImpl2 and PathImpl as inlined below :

nestjs-i18n/src/types.ts

Lines 27 to 33 in 6b1bb3a

export type Path<T> = keyof T extends string
? PathImpl2<T> extends infer P
? P extends string | keyof T
? P
: keyof T
: keyof T
: never;

This makes it awkward to use the generated keys, and I've barely started translating my app I'm already having way too many entries in the intellisense (so much that I'm currently disabling the generated typings option in favour of a vscode extension, which makes my app error-prone at typescript's compile time).

I believe this especially happens with nested keys (see example below), but I could be wrong on this as I haven't tested every single scenario yet.

image

Reproduction

Even the starter example with few nested keys does it

System Info

System:
    OS: Linux 5.10 Debian GNU/Linux 11 (bullseye) 11 (bullseye)
    CPU: (24) x64 AMD Ryzen 9 5900X 12-Core Processor
    Memory: 247.43 MB / 3.83 GB
    Container: Yes
    Shell: 5.1.4 - /bin/bash
  Binaries:
    Node: 18.17.1 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 9.8.1 - /usr/local/bin/npm
    pnpm: 8.8.0 - /usr/local/share/npm-global/bin/pnpm

Used Package Manager

pnpm

Validations

  • Follow our Code of Conduct
  • Read the Contributing Guide.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • Check that this is a concrete bug. For Q&A, please open a GitHub Discussion instead.
  • The provided reproduction is a minimal reproducible of the bug.
V-ed added a commit to ved-websites/fullstacked that referenced this issue Oct 5, 2023
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