- 
                Notifications
    You must be signed in to change notification settings 
- Fork 718
feat(types): add generic type parameters to changelog functions #1723
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
base: main
Are you sure you want to change the base?
feat(types): add generic type parameters to changelog functions #1723
Conversation
| 🦋 Changeset detectedLatest commit: b020a8f The changes in this PR will be included in the next version bump. This PR includes changesets to release 15 packages
 Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR | 
| Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@           Coverage Diff           @@
##             main    #1723   +/-   ##
=======================================
  Coverage   80.69%   80.69%           
=======================================
  Files          54       54           
  Lines        2264     2264           
  Branches      684      685    +1     
=======================================
  Hits         1827     1827           
  Misses        432      432           
  Partials        5        5           ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
 | 
ef037e6    to
    5079591      
    Compare
  
    Enhances type safety by allowing changelog generators to specify custom option types instead of using generic any types fixes changesets#1722
5079591    to
    5273f58      
    Compare
  
    | @Ari4ka I updated updated the branch so it it even with main. Thanks for reviewing. | 
| The description of this PR mentions: 
 But what is being introduced here, let's be real, is kind of a cast that disguises itself as being safe. The type safe alternative would be to just type params as  | 
| @Andarist If I understand you correctly, this solution is not true type safety because the shape of the argument is being parsed from JSON and we can't enforce that at runtime. My solution of converting the types to be generics with a default value like it was before was simply for the ergonomics of developers working on their own changelog systems. Would an acceptable compromise be for me to make a note of this issue in the JSDoc comments and demonstrate validating the shape of the argument in an  | 
| This kind of a thing is ultimately always a decision up to personal tastes. Many APIs out there compromise type-safety in favor of improved ergonomics. I can sympathize with that goal but I'm not sure if I end up on the same side of this argument. The problem with this is that it's an illusion of type-safety - you, as author of this change, will understand the risks. I'll understand the risks, some of the skilled devs will understand the risks and people who read the docs might also understand the risks. But those combined groups do not constitute all developers of Changesets. I recognize the current types there aren't really safe anyway but I just think it would be better to change those in the future to  const myChangelog: ChangelogFunctions = {
  getReleaseLine: async (changeset, type, _options) => {
    const options = _options as { repo: string };
    return `- ${changeset.summary}`;
  },
};I know it's slightly worse but at least the true behavior of this code isn't hidden/tucked away. | 
| @Andarist I see what you are saying. I was just working on a Changelog generator in TypeScript and found this hard to grok and thought perhaps adding this sugar would help other developers. I would still advocate for adding this as it doesn't change the current API at all. All the hidden perils of not validating the options input still exist, both before and after, but at least there is clearer indication about what is happening. I am just trying to be helpful, but if this isn't something you are interested in adding, I totally understand. | 
Enhances type safety by allowing changelog generators to specify custom option types instead of using generic any types
fixes #1722