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

FR: Change YAMLMap to support non record types #535

Open
inlined opened this issue Apr 9, 2024 · 1 comment
Open

FR: Change YAMLMap to support non record types #535

inlined opened this issue Apr 9, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@inlined
Copy link

inlined commented Apr 9, 2024

Is your feature request related to a problem? Please describe.
YAML documents often have a structure with known key types turning into known value types. The current YAMLMap type is based on a Record type which means any key of the input object maps to any value of the input object.

Describe the solution you'd like
Change the template type for YAMLMap from YAMLMap<K = unknown, V = unknown> to YAMLMap<T extends Record<unknown, unknown>> and propagate types, E.g. YAMLMap<T>::get<S extends keyof T>(key: S, keepScalar?: false): T[S]

This will both prevent typos in "get" calls, and remove unnecessary undefined checks if the schema ensures a value is present.

Describe alternatives you've considered
Keep losing type information as I navigate the document

Additional context
Chose this library because of its support for incremental changes to YAML, which will let me modify config files with minimal diffs. This was clearly a lot of hard work to expose this library and I appreciate what you've done so far 😄

@inlined inlined added the enhancement New feature or request label Apr 9, 2024
@eemeli
Copy link
Owner

eemeli commented Apr 9, 2024

Sounds like a pretty good idea. I'd be happy to consider a PR for this.

Note that the current compiled types are tested to work in TS 3.9 or later; sticking to that is not a hard limit, we can increase the minimum in a minor version update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants