denosaurs / denosaurs/typefetch

Make URLs a generic type

Open
#16 0 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
TypeScript
Stars
21
Forks
1
PR merge metrics
No merged PRs in 30d

Description

Currently the URLs can get quite messy in cases where we support both relative, server and absolute urls. E.g:

```typescript
...
input:
| `${"http://" | "https://"}${string}/api/v1/${string}/subscription/plan/${string}/subscribe/`
| `/api/v1/${string}/subscription/plan/${string}/subscribe/`,
...
```

It would be nice if these types would look like:

```typescript
TypedURL<`/api/v1/${string}/subscription/plan/${string}/subscribe/`>
```

This could then be generated per-project like:

```typescript
export type TypedURL =
| `https://example.com/${T}` // Include each server URL here
| `http://${string}${T}` // Include only when absolute http URLs are enabled
| `https://${string}${T}` // Include only when absolute https URLs are enabled
| T; // Include only when relative URLs are enabled
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.