Skip to content

[$250] [Cleanup] Utility URL type for getURLWithBackParam, etc... #32143

@roryabraham

Description

@roryabraham

Coming from #31543 (comment)...

Problem

We've got some types that look like this:

function getUrlWithBackToParam<TUrl extends string>(url: TUrl, backTo?: string): `${TUrl}` | `${TUrl}?backTo=${string}` | `${TUrl}&backTo=${string}` {
    ...
}

and while that works it's a pretty verbose way to express a pretty common format for something.

Solution

This is a rich representation of what this string could / should look like, instead of just being string, but let's clean this up to make it more extensible/reusable. We should make a utility type for URLs that takes:

  • A base URL
  • an object type representing a series of optional or required query params (which of course can be in any order)

Then the resultant type would be any string matching the pattern of a valid URL with the correct base and query params.

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~01ab405b1ad68ca814
  • Upwork Job ID: 1729557018701299712
  • Last Price Increase: 2023-11-28

Metadata

Metadata

Labels

DailyKSv2ExternalAdded to denote the issue can be worked on by a contributorNewFeatureSomething to build that is a new item.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions