Skip to content

Prevent then from being called after end#66

Open
jleider wants to merge 2 commits into
gcanti:masterfrom
jleider:no-then-after-end
Open

Prevent then from being called after end#66
jleider wants to merge 2 commits into
gcanti:masterfrom
jleider:no-then-after-end

Conversation

@jleider
Copy link
Copy Markdown

@jleider jleider commented Jun 8, 2022

Calling then after end with additional routing parameters the router leads to some unexpected runtime behavior. This change prevents the possibility of then being chained after an end.

The main difference here is the addition of a MatchEnd<A> type which does not contain an imap or then function. If anyone has a better idea of what to name this type or another approach I am happy to entertain alternative ideas.

One thing to note, this is a breaking change so I have bumped the version to 0.6.0 which I believe due to semantic versioning is acceptable due to this package being below 1.0.0.

Comment thread CHANGELOG.md
**Note**: Gaps between patch versions are faulty/broken releases. **Note**: A feature tagged as Experimental is in a
high state of flux, you're at risk of it changing without notice.

# 0.6.0
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@jleider we will bump the package's version and add the entry in the changelog just before publish the v0.6.0

Comment thread src/index.ts
}

end(): MatchEnd<A> {
return this.then(new Match(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@jleider this will return a Match<A & {}> and raises this TS error:

Type 'Match<A & {}>' is not assignable to type 'MatchEnd<A>'

Comment thread src/index.ts
* @since 0.4.0
*/
export const end: Match<{}> = new Match(
export const end: MatchEnd<{}> = new MatchEnd(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@jleider this implementation will break existing code which uses end like that:

.then(end)
// Throws:
// Argument of type 'MatchEnd<{}>' is not assignable to parameter of type 'Match<{}> & Match<Record<never, never>>'.ts(2345)

Even if the package's version is below 1.0.0, the library has been published from quite a lot by now and we have to be as careful as possible

@StefanoMagrassi StefanoMagrassi removed this from the 0.6 milestone Jun 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants