Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

typescript-fetch

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

typescript-fetch - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

6

CHANGELOG.md
# typescript-fetch
## 0.0.4
### Patch Changes
- [`3eb5546`](https://github.com/jacob-ebey/typescript-fetch/commit/3eb554685e6490f2b79e574d458deb52e6472b79) Thanks [@jacob-ebey](https://github.com/jacob-ebey)! - add typed URL
## 0.0.3

@@ -4,0 +10,0 @@

3

dist/index.js

@@ -0,1 +1,4 @@

export function typedURL(request) {
return new URL(request.url);
}
export function typeRequest(input, init) {

@@ -2,0 +5,0 @@ return new Request(input, init);

@@ -1,3 +0,4 @@

import { typedRequest } from ".";
import { typedRequest, typedURL, } from ".";
export function fetchTests() {
function assertRequest(_request) { }
// Should be able to type basic Requests

@@ -23,2 +24,7 @@ assertRequest(typedRequest("https://.../test"));

assertPath("/.../.../");
function assertTypedURL(_url) { }
assertTypedURL(typedURL(null));
assertTypedURL(typedURL(null));
assertTypedURL(typedURL(null));
assertTypedURL(typedURL(null));
}

@@ -39,8 +39,50 @@ import { Jsonifiable, Jsonify } from "type-fest";

export interface TypedURLSearchParams<Key extends string>
extends globalThis.URLSearchParams {
append(name: Key, value: string): void;
delete(name: Key): void;
get(name: Key): string | null;
getAll(name: Key): string[];
has(name: Key): boolean;
set(name: Key, value: string): void;
}
export interface TypedURL<
Pathname extends PathnameFormat,
SearchParamKeys extends string
> {
href: URLFormat<Pathname>;
searchParams: TypedURLSearchParams<SearchParamKeys>;
}
export function typedURL<Request extends TypedRequest<any, any>>(
request: Request
) {
return new URL(request.url) as Request extends TypedRequest<
any,
infer Pathname,
infer SearchParamKeys
>
? TypedURL<inferPath<Pathname>, SearchParamKeys>
: unknown;
}
export interface TypedFormData<Key extends string> extends globalThis.FormData {
append(key: Key, value: FormDataEntryValue, fileName?: string): void;
delete(key: Key): void;
get(key: Key): FormDataEntryValue | null;
getAll(key: Key): FormDataEntryValue[];
has(key: Key): boolean;
set(key: Key, value: FormDataEntryValue, fileName?: string): void;
}
export interface TypedRequest<
Method extends RequestMethod,
Pathname extends string
Pathname extends string,
SearchParamKeys extends string = string,
FormDataKeys extends string = string
> extends globalThis.Request {
method: Method;
url: URLFormat<inferPath<Pathname>>;
formData(): Promise<TypedFormData<FormDataKeys>>;
}

@@ -47,0 +89,0 @@

2

package.json
{
"name": "typescript-fetch",
"version": "0.0.3",
"version": "0.0.4",
"main": "dist/index.js",

@@ -5,0 +5,0 @@ "types": "dist/index.d.ts",

@@ -1,9 +0,15 @@

import { typedRequest, type TypedRequest, type inferPath } from ".";
import {
typedRequest,
typedURL,
type TypedRequest,
type TypedURL,
type inferPath,
} from ".";
declare function assertRequest<
TR extends TypedRequest<any, any>,
TR2 extends TR = TR
>(_request: TR2): void;
export function fetchTests() {
function assertRequest<
TR extends TypedRequest<any, any>,
TR2 extends TR = TR
>(_request: TR2) {}
export function fetchTests() {
// Should be able to type basic Requests

@@ -33,2 +39,17 @@ assertRequest<TypedRequest<"GET", "/test">>(typedRequest("https://.../test"));

assertPath<inferPath<"/*">>("/.../.../");
function assertTypedURL<TU extends TypedURL<any, any>>(_url: TU) {}
assertTypedURL<TypedURL<inferPath<"/">, never>>(
typedURL(null as unknown as TypedRequest<"GET", "/">)
);
assertTypedURL<TypedURL<inferPath<"/">, "">>(
typedURL(null as unknown as TypedRequest<"GET", "/">)
);
assertTypedURL<TypedURL<inferPath<"/">, "a">>(
typedURL(null as unknown as TypedRequest<"GET", "/", "a">)
);
assertTypedURL<TypedURL<inferPath<"/">, "a" | "b">>(
typedURL(null as unknown as TypedRequest<"GET", "/", "a" | "b">)
);
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc