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

feat: yaml options #144

Merged
merged 4 commits into from
Aug 27, 2024
Merged

feat: yaml options #144

merged 4 commits into from
Aug 27, 2024

Conversation

urugator
Copy link
Contributor

@urugator urugator commented Aug 26, 2024

Types are copied from yaml repo:

export declare function stringify(value: any, replacer?: Replacer | null, options?: string | number | (DocumentOptions & SchemaOptions & ParseOptions & CreateNodeOptions & ToStringOptions)): string;

To keep things simple and in line with getSpecAsJson the signature with options only (without replacer) is not supported.

Fixes: #143

Comment on lines 49 to 58
// eslint-disable-next-line @typescript-eslint/no-explicit-any
replacer?: any[] | ((key: any, value: any) => unknown) | null,
options?:
| string
| number
| (yaml.DocumentOptions &
yaml.SchemaOptions &
yaml.ParseOptions &
yaml.CreateNodeOptions &
yaml.ToStringOptions)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest to make a reference to the types of the yaml.stringify() parameters instead

Copy link
Contributor

@RobinTail RobinTail Aug 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// eslint-disable-next-line @typescript-eslint/no-explicit-any
replacer?: any[] | ((key: any, value: any) => unknown) | null,
options?:
| string
| number
| (yaml.DocumentOptions &
yaml.SchemaOptions &
yaml.ParseOptions &
yaml.CreateNodeOptions &
yaml.ToStringOptions)
replacer?: Parameters<typeof yaml.stringify>[1],
options?: Parameters<typeof yaml.stringify>[2]

then you'd not need:

  • to reproduce internal typing of another module
  • to mute ESLint error

That will also make it future resistant (maintainability) if yaml dependency upgrades with changed types, @urugator

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to do that, but it's is not doable for overloaded functions, because TS doesn't know which overload to pick.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pick the one having replacer, consider Extract for that, @urugator

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dunno what you mean with the Extract, but turns out Parameters are parameters of the last signature, which is the one we need. So unless they swap or introduce new signatures it should be fine I guess.

Comment on lines 49 to 58
// eslint-disable-next-line @typescript-eslint/no-explicit-any
replacer?: any[] | ((key: any, value: any) => unknown) | null,
options?:
| string
| number
| (yaml.DocumentOptions &
yaml.SchemaOptions &
yaml.ParseOptions &
yaml.CreateNodeOptions &
yaml.ToStringOptions)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changelog.md Outdated
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say it's too much changes to this file that are unrelated to the proposed feature.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's done by prettier, should I add Changelog.md to prettier ignore?

Copy link
Contributor

@RobinTail RobinTail left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggesting to use Parameters<typeof yaml.stringify>
https://www.typescriptlang.org/docs/handbook/utility-types.html#parameterstype

Copy link
Contributor

@RobinTail RobinTail left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

@pjmolina pjmolina merged commit 406f3c2 into metadevpro:master Aug 27, 2024
2 checks passed
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

Successfully merging this pull request may close these issues.

Reusing object references produces anchors and aliases in yaml
3 participants